<!-- HTML header for doxygen 1.8.11-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>i2cpwm_board: src/i2cpwm_controller.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <a href="./index.html"><div id="projectname">i2cpwm_board
   &#160;<span id="projectnumber">0.5.1</span>
   </div></a>
   <div id="projectbrief">ROS Package for PCA9685 based 16 channel PWM Board with I2C Interface</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">i2cpwm_controller.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="i2cpwm__controller_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;<span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;<span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;<span class="preprocessor">#include &lt;math.h&gt;</span></div><div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;<span class="preprocessor">#include &lt;fcntl.h&gt;</span></div><div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;<span class="preprocessor">#include &lt;errno.h&gt;</span></div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;<span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;<span class="preprocessor">#include &lt;sys/ioctl.h&gt;</span></div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;<span class="preprocessor">#include &lt;sys/types.h&gt;</span></div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;<span class="preprocessor">#include &lt;sys/stat.h&gt;</span></div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;<span class="preprocessor">#include &lt;linux/i2c-dev.h&gt;</span></div><div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;</div><div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;<span class="preprocessor">#include &lt;ros/ros.h&gt;</span></div><div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;<span class="preprocessor">#include &lt;ros/console.h&gt;</span></div><div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;</div><div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;<span class="comment">// messages used for any service with no parameters</span></div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;<span class="preprocessor">#include &lt;std_srvs/Empty.h&gt;</span></div><div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;<span class="comment">// messages used for drive movement topic</span></div><div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;<span class="preprocessor">#include &lt;geometry_msgs/Twist.h&gt;</span></div><div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;</div><div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;<span class="comment">// messages used for the absolute and proportional movement topics</span></div><div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;<span class="preprocessor">#include &quot;i2cpwm_board/Servo.h&quot;</span></div><div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;<span class="preprocessor">#include &quot;i2cpwm_board/ServoArray.h&quot;</span></div><div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;<span class="comment">// messages used for the servo setup service</span></div><div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;<span class="preprocessor">#include &quot;i2cpwm_board/ServoConfig.h&quot;</span></div><div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;<span class="preprocessor">#include &quot;i2cpwm_board/ServoConfigArray.h&quot;</span></div><div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;<span class="comment">// request/response of the servo setup service</span></div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;<span class="preprocessor">#include &quot;i2cpwm_board/ServosConfig.h&quot;</span></div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;<span class="comment">// request/response of the drive mode service</span></div><div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;<span class="preprocessor">#include &quot;i2cpwm_board/DriveMode.h&quot;</span></div><div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;<span class="preprocessor">#include &quot;i2cpwm_board/Position.h&quot;</span></div><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;<span class="preprocessor">#include &quot;i2cpwm_board/PositionArray.h&quot;</span></div><div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;<span class="comment">// request/response of the integer parameter services</span></div><div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;<span class="preprocessor">#include &quot;i2cpwm_board/IntValue.h&quot;</span></div><div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;</div><div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;</div><div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;</div><div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;<span class="keyword">typedef</span> <span class="keyword">struct </span>_servo_config {</div><div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;    <span class="keywordtype">int</span> center;</div><div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;    <span class="keywordtype">int</span> range;</div><div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;    <span class="keywordtype">int</span> direction;</div><div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;    <span class="keywordtype">int</span> mode_pos;</div><div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;} servo_config;</div><div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;</div><div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;<span class="keyword">typedef</span> <span class="keyword">struct </span>_drive_mode {</div><div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;    <span class="keywordtype">int</span> mode;</div><div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;    <span class="keywordtype">float</span> rpm;</div><div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;    <span class="keywordtype">float</span> radius;</div><div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;    <span class="keywordtype">float</span> track;</div><div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;    <span class="keywordtype">float</span> scale;</div><div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;} drive_mode;</div><div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;</div><div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;<span class="keyword">enum</span> drive_modes {</div><div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;    MODE_UNDEFINED      = 0,</div><div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;    MODE_ACKERMAN       = 1,</div><div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;    MODE_DIFFERENTIAL   = 2,</div><div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;    MODE_MECANUM        = 3,</div><div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;    MODE_INVALID        = 4</div><div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;};</div><div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;</div><div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;<span class="keyword">enum</span> drive_mode_positions {</div><div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;    POSITION_UNDEFINED  = 0,</div><div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;    POSITION_LEFTFRONT  = 1,</div><div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;    POSITION_RIGHTFRONT = 2,</div><div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;    POSITION_LEFTREAR   = 3,</div><div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;    POSITION_RIGHTREAR  = 4,</div><div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;    POSITION_INVALID    = 5</div><div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;};</div><div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;</div><div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;<span class="preprocessor">#define _BASE_ADDR   0x40</span></div><div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;<span class="preprocessor">#ifndef _PI</span></div><div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;<span class="preprocessor">#define _PI 3.14159265358979323846</span></div><div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;<span class="preprocessor">#define _CONST(s) ((char*)(s))</span></div><div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;</div><div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;<span class="keyword">enum</span> pwm_regs {</div><div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;  <span class="comment">// Registers/etc.</span></div><div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;  __MODE1              = 0x00,</div><div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;  __MODE2              = 0x01,</div><div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;  __SUBADR1            = 0x02,      <span class="comment">// enable sub address 1 support</span></div><div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;  __SUBADR2            = 0x03,      <span class="comment">// enable sub address 2 support</span></div><div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;  __SUBADR3            = 0x04,      <span class="comment">// enable sub address 2 support</span></div><div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;  __PRESCALE           = 0xFE,</div><div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;  __CHANNEL_ON_L       = 0x06,</div><div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;  __CHANNEL_ON_H       = 0x07,</div><div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;  __CHANNEL_OFF_L      = 0x08,</div><div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;  __CHANNEL_OFF_H      = 0x09,</div><div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;  __ALL_CHANNELS_ON_L  = 0xFA,</div><div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;  __ALL_CHANNELS_ON_H  = 0xFB,</div><div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;  __ALL_CHANNELS_OFF_L = 0xFC,</div><div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;  __ALL_CHANNELS_OFF_H = 0xFD,</div><div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;  __RESTART            = 0x80,</div><div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;  __SLEEP              = 0x10,      <span class="comment">// enable low power mode</span></div><div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;  __ALLCALL            = 0x01,</div><div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;  __INVRT              = 0x10,      <span class="comment">// invert the output control logic</span></div><div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;  __OUTDRV             = 0x04</div><div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;};</div><div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;</div><div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;<span class="preprocessor">#define MAX_BOARDS 62</span></div><div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;<span class="preprocessor">#define MAX_SERVOS (16*MAX_BOARDS)</span></div><div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;</div><div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;servo_config _servo_configs[MAX_SERVOS];    <span class="comment">// we can support up to 62 boards (1..62), each with 16 PWM devices (1..16)</span></div><div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;drive_mode _active_drive;                   <span class="comment">// used when converting Twist geometry to PWM values and which servos are for motion</span></div><div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;<span class="keywordtype">int</span> _last_servo = -1;</div><div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;</div><div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;<span class="keywordtype">int</span> _pwm_boards[MAX_BOARDS];                <span class="comment">// we can support up to 62 boards (1..62)</span></div><div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;<span class="keywordtype">int</span> _active_board = 0;                      <span class="comment">// used to determine if I2C SLAVE change is needed</span></div><div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;<span class="keywordtype">int</span> _controller_io_handle;                  <span class="comment">// linux file handle for I2C</span></div><div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;</div><div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;<span class="keywordtype">int</span> _pwm_frequency = 50;                    <span class="comment">// frequency determines the size of a pulse width; higher numbers make RC servos buzz</span></div><div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;</div><div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;</div><div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;</div><div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;</div><div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;</div><div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;<span class="comment">//* ------------------------------------------------------------------------------------------------------------------------------------</span></div><div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;<span class="comment">// local private methods</span></div><div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;<span class="comment">//* ------------------------------------------------------------------------------------------------------------------------------------</span></div><div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;</div><div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;<span class="keyword">static</span> <span class="keywordtype">float</span> _abs (<span class="keywordtype">float</span> v1)</div><div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;{</div><div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;    <span class="keywordflow">if</span> (v1 &lt; 0)</div><div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;        <span class="keywordflow">return</span> (0 - v1);</div><div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;    <span class="keywordflow">return</span> v1;</div><div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;}</div><div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;</div><div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;<span class="keyword">static</span> <span class="keywordtype">float</span> _min (<span class="keywordtype">float</span> v1, <span class="keywordtype">float</span> v2)</div><div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;{</div><div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;    <span class="keywordflow">if</span> (v1 &gt; v2)</div><div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;        <span class="keywordflow">return</span> v2;</div><div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;    <span class="keywordflow">return</span> v1;</div><div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;}</div><div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;</div><div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;<span class="keyword">static</span> <span class="keywordtype">float</span> _max (<span class="keywordtype">float</span> v1, <span class="keywordtype">float</span> v2)</div><div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;{</div><div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;    <span class="keywordflow">if</span> (v1 &lt; v2)</div><div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;        <span class="keywordflow">return</span> v2;</div><div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;    <span class="keywordflow">return</span> v1;</div><div class="line"><a name="l00309"></a><span class="lineno">  309</span>&#160;}</div><div class="line"><a name="l00310"></a><span class="lineno">  310</span>&#160;</div><div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;<span class="keyword">static</span> <span class="keywordtype">float</span> _absmin (<span class="keywordtype">float</span> v1, <span class="keywordtype">float</span> v2)</div><div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;{</div><div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;    <span class="keywordtype">float</span> a1, a2;</div><div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;    <span class="keywordtype">float</span> sign = 1.0;</div><div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;    <span class="comment">//  if (v1 &lt; 0)</span></div><div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;    <span class="comment">//      sign = -1.0;</span></div><div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;    a1 = _abs(v1);</div><div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;    a2 = _abs(v2);</div><div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;    <span class="keywordflow">if</span> (a1 &gt; a2)</div><div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;        <span class="keywordflow">return</span> (sign * a2);</div><div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;    <span class="keywordflow">return</span> v1;</div><div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;}</div><div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;</div><div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;<span class="keyword">static</span> <span class="keywordtype">float</span> _absmax (<span class="keywordtype">float</span> v1, <span class="keywordtype">float</span> v2)</div><div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;{</div><div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;    <span class="keywordtype">float</span> a1, a2;</div><div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;    <span class="keywordtype">float</span> sign = 1.0;</div><div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;    <span class="comment">//  if (v1 &lt; 0)</span></div><div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;    <span class="comment">//      sign = -1.0;</span></div><div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;    a1 = _abs(v1);</div><div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;    a2 = _abs(v2);</div><div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;    <span class="keywordflow">if</span> (a1 &lt; a2)</div><div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;        <span class="keywordflow">return</span> (sign * a2);</div><div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;    <span class="keywordflow">return</span> v1;</div><div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;}</div><div class="line"><a name="l00336"></a><span class="lineno">  336</span>&#160;</div><div class="line"><a name="l00337"></a><span class="lineno">  337</span>&#160;</div><div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160;</div><div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _smoothing (<span class="keywordtype">float</span> speed)</div><div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;{</div><div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;    <span class="comment">/* if smoothing is desired, then remove the commented code  */</span></div><div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;    <span class="comment">// speed = (cos(_PI*(((float)1.0 - speed))) + 1) / 2;</span></div><div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;    <span class="keywordflow">return</span> speed;</div><div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;}</div><div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;    </div><div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;</div><div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;<span class="keyword">static</span> <span class="keywordtype">float</span> _convert_mps_to_proportional (<span class="keywordtype">float</span> speed)</div><div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;{</div><div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;    <span class="comment">/* we use the drive mouter output rpm and wheel radius to compute the conversion */</span></div><div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160;</div><div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;    <span class="keywordtype">float</span> initial, max_rate;    <span class="comment">// the max m/s is ((rpm/60) * (2*PI*radius))</span></div><div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;</div><div class="line"><a name="l00369"></a><span class="lineno">  369</span>&#160;    initial = speed;</div><div class="line"><a name="l00370"></a><span class="lineno">  370</span>&#160;    </div><div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;    <span class="keywordflow">if</span> (_active_drive.rpm &lt;= 0.0) {</div><div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid active drive mode RPM %6.4f :: RPM must be greater than 0&quot;</span>, _active_drive.rpm);</div><div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;        <span class="keywordflow">return</span> 0.0;</div><div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;    }</div><div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;    <span class="keywordflow">if</span> (_active_drive.radius &lt;= 0.0) {</div><div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid active drive mode radius %6.4f :: wheel radius must be greater than 0&quot;</span>, _active_drive.radius);</div><div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;        <span class="keywordflow">return</span> 0.0;</div><div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;    }</div><div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;</div><div class="line"><a name="l00380"></a><span class="lineno">  380</span>&#160;    max_rate = (_active_drive.radius * _PI * 2) * (_active_drive.rpm / 60.0);</div><div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;</div><div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;    speed = speed / max_rate;</div><div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;    <span class="comment">// speed = _absmin (speed, 1.0);</span></div><div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;</div><div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;    ROS_DEBUG(<span class="stringliteral">&quot;%6.4f = convert_mps_to_proportional ( speed(%6.4f) / ((radus(%6.4f) * pi(%6.4f) * 2) * (rpm(%6.4f) / 60.0)) )&quot;</span>, speed, initial, _active_drive.radius, _PI, _active_drive.rpm);</div><div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;    <span class="keywordflow">return</span> speed;</div><div class="line"><a name="l00387"></a><span class="lineno">  387</span>&#160;}</div><div class="line"><a name="l00388"></a><span class="lineno">  388</span>&#160;</div><div class="line"><a name="l00389"></a><span class="lineno">  389</span>&#160;</div><div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;</div><div class="line"><a name="l00398"></a><span class="lineno">  398</span>&#160;<span class="keyword">static</span> <span class="keywordtype">void</span> _set_pwm_frequency (<span class="keywordtype">int</span> freq)</div><div class="line"><a name="l00399"></a><span class="lineno">  399</span>&#160;{</div><div class="line"><a name="l00400"></a><span class="lineno">  400</span>&#160;    <span class="keywordtype">int</span> prescale;</div><div class="line"><a name="l00401"></a><span class="lineno">  401</span>&#160;    <span class="keywordtype">char</span> oldmode, newmode;</div><div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160;    <span class="keywordtype">int</span> res;</div><div class="line"><a name="l00403"></a><span class="lineno">  403</span>&#160;</div><div class="line"><a name="l00404"></a><span class="lineno">  404</span>&#160;    _pwm_frequency = freq;   <span class="comment">// save to global</span></div><div class="line"><a name="l00405"></a><span class="lineno">  405</span>&#160;    </div><div class="line"><a name="l00406"></a><span class="lineno">  406</span>&#160;    ROS_DEBUG(<span class="stringliteral">&quot;_set_pwm_frequency prescale&quot;</span>);</div><div class="line"><a name="l00407"></a><span class="lineno">  407</span>&#160;    <span class="keywordtype">float</span> prescaleval = 25000000.0; <span class="comment">// 25MHz</span></div><div class="line"><a name="l00408"></a><span class="lineno">  408</span>&#160;    prescaleval /= 4096.0;</div><div class="line"><a name="l00409"></a><span class="lineno">  409</span>&#160;    prescaleval /= (float)freq;</div><div class="line"><a name="l00410"></a><span class="lineno">  410</span>&#160;    prescaleval -= 1.0;</div><div class="line"><a name="l00411"></a><span class="lineno">  411</span>&#160;    <span class="comment">//ROS_INFO(&quot;Estimated pre-scale: %6.4f&quot;, prescaleval);</span></div><div class="line"><a name="l00412"></a><span class="lineno">  412</span>&#160;    prescale = floor(prescaleval + 0.5);</div><div class="line"><a name="l00413"></a><span class="lineno">  413</span>&#160;    <span class="comment">// ROS_INFO(&quot;Final pre-scale: %d&quot;, prescale);</span></div><div class="line"><a name="l00414"></a><span class="lineno">  414</span>&#160;</div><div class="line"><a name="l00415"></a><span class="lineno">  415</span>&#160;</div><div class="line"><a name="l00416"></a><span class="lineno">  416</span>&#160;    ROS_INFO(<span class="stringliteral">&quot;Setting PWM frequency to %d Hz&quot;</span>, freq);</div><div class="line"><a name="l00417"></a><span class="lineno">  417</span>&#160;</div><div class="line"><a name="l00418"></a><span class="lineno">  418</span>&#160;    nanosleep ((<span class="keyword">const</span> <span class="keyword">struct</span> timespec[]){{1, 000000L}}, NULL); </div><div class="line"><a name="l00419"></a><span class="lineno">  419</span>&#160;</div><div class="line"><a name="l00420"></a><span class="lineno">  420</span>&#160;</div><div class="line"><a name="l00421"></a><span class="lineno">  421</span>&#160;    oldmode = i2c_smbus_read_byte_data (_controller_io_handle, __MODE1);</div><div class="line"><a name="l00422"></a><span class="lineno">  422</span>&#160;    newmode = (oldmode &amp; 0x7F) | 0x10; <span class="comment">// sleep</span></div><div class="line"><a name="l00423"></a><span class="lineno">  423</span>&#160;</div><div class="line"><a name="l00424"></a><span class="lineno">  424</span>&#160;    <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __MODE1, newmode)) <span class="comment">// go to sleep</span></div><div class="line"><a name="l00425"></a><span class="lineno">  425</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Unable to set PWM controller to sleep mode&quot;</span>); </div><div class="line"><a name="l00426"></a><span class="lineno">  426</span>&#160;</div><div class="line"><a name="l00427"></a><span class="lineno">  427</span>&#160;    <span class="keywordflow">if</span> (0 &gt;  i2c_smbus_write_byte_data(_controller_io_handle, __PRESCALE, (<span class="keywordtype">int</span>)(floor(prescale))))</div><div class="line"><a name="l00428"></a><span class="lineno">  428</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Unable to set PWM controller prescale&quot;</span>); </div><div class="line"><a name="l00429"></a><span class="lineno">  429</span>&#160;</div><div class="line"><a name="l00430"></a><span class="lineno">  430</span>&#160;    <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data(_controller_io_handle, __MODE1, oldmode))</div><div class="line"><a name="l00431"></a><span class="lineno">  431</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Unable to set PWM controller to active mode&quot;</span>); </div><div class="line"><a name="l00432"></a><span class="lineno">  432</span>&#160;</div><div class="line"><a name="l00433"></a><span class="lineno">  433</span>&#160;    nanosleep((<span class="keyword">const</span> <span class="keyword">struct</span> timespec[]){{0, 5000000L}}, NULL);   <span class="comment">//sleep 5microsec,</span></div><div class="line"><a name="l00434"></a><span class="lineno">  434</span>&#160;</div><div class="line"><a name="l00435"></a><span class="lineno">  435</span>&#160;    <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data(_controller_io_handle, __MODE1, oldmode | 0x80))</div><div class="line"><a name="l00436"></a><span class="lineno">  436</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Unable to restore PWM controller to active mode&quot;</span>);</div><div class="line"><a name="l00437"></a><span class="lineno">  437</span>&#160;}</div><div class="line"><a name="l00438"></a><span class="lineno">  438</span>&#160;</div><div class="line"><a name="l00439"></a><span class="lineno">  439</span>&#160;</div><div class="line"><a name="l00440"></a><span class="lineno">  440</span>&#160;</div><div class="line"><a name="l00449"></a><span class="lineno">  449</span>&#160;<span class="keyword">static</span> <span class="keywordtype">void</span> _set_pwm_interval_all (<span class="keywordtype">int</span> start, <span class="keywordtype">int</span> end)</div><div class="line"><a name="l00450"></a><span class="lineno">  450</span>&#160;{</div><div class="line"><a name="l00451"></a><span class="lineno">  451</span>&#160;    <span class="comment">// the public API is ONE based and hardware is ZERO based</span></div><div class="line"><a name="l00452"></a><span class="lineno">  452</span>&#160;    <span class="keywordflow">if</span> ((_active_board&lt;1) || (_active_board&gt;62)) {</div><div class="line"><a name="l00453"></a><span class="lineno">  453</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Internal error - invalid active board number %d :: PWM board numbers must be between 1 and 62&quot;</span>, _active_board);</div><div class="line"><a name="l00454"></a><span class="lineno">  454</span>&#160;        <span class="keywordflow">return</span>;</div><div class="line"><a name="l00455"></a><span class="lineno">  455</span>&#160;    }</div><div class="line"><a name="l00456"></a><span class="lineno">  456</span>&#160;    <span class="keywordtype">int</span> board = _active_board - 1;</div><div class="line"><a name="l00457"></a><span class="lineno">  457</span>&#160;</div><div class="line"><a name="l00458"></a><span class="lineno">  458</span>&#160;    <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __ALL_CHANNELS_ON_L, start &amp; 0xFF))</div><div class="line"><a name="l00459"></a><span class="lineno">  459</span>&#160;        ROS_ERROR (<span class="stringliteral">&quot;Error setting PWM start low byte for all servos on board %d&quot;</span>, _active_board);</div><div class="line"><a name="l00460"></a><span class="lineno">  460</span>&#160;    <span class="keywordflow">if</span> (0 &gt;  i2c_smbus_write_byte_data (_controller_io_handle, __ALL_CHANNELS_ON_H, start  &gt;&gt; 8))</div><div class="line"><a name="l00461"></a><span class="lineno">  461</span>&#160;        ROS_ERROR (<span class="stringliteral">&quot;Error setting PWM start high byte for all servos on board %d&quot;</span>, _active_board);</div><div class="line"><a name="l00462"></a><span class="lineno">  462</span>&#160;    <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __ALL_CHANNELS_OFF_L, end &amp; 0xFF))</div><div class="line"><a name="l00463"></a><span class="lineno">  463</span>&#160;        ROS_ERROR (<span class="stringliteral">&quot;Error setting PWM end low byte for all servos on board %d&quot;</span>, _active_board);</div><div class="line"><a name="l00464"></a><span class="lineno">  464</span>&#160;    <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __ALL_CHANNELS_OFF_H, end &gt;&gt; 8))</div><div class="line"><a name="l00465"></a><span class="lineno">  465</span>&#160;        ROS_ERROR (<span class="stringliteral">&quot;Error setting PWM end high byte for all servos on board %d&quot;</span>, _active_board);</div><div class="line"><a name="l00466"></a><span class="lineno">  466</span>&#160;}</div><div class="line"><a name="l00467"></a><span class="lineno">  467</span>&#160;</div><div class="line"><a name="l00468"></a><span class="lineno">  468</span>&#160;</div><div class="line"><a name="l00469"></a><span class="lineno">  469</span>&#160;</div><div class="line"><a name="l00476"></a><span class="lineno">  476</span>&#160;<span class="keyword">static</span> <span class="keywordtype">void</span> _set_active_board (<span class="keywordtype">int</span> board)</div><div class="line"><a name="l00477"></a><span class="lineno">  477</span>&#160;{</div><div class="line"><a name="l00478"></a><span class="lineno">  478</span>&#160;    <span class="keywordtype">char</span> mode1res;</div><div class="line"><a name="l00479"></a><span class="lineno">  479</span>&#160;</div><div class="line"><a name="l00480"></a><span class="lineno">  480</span>&#160;    <span class="keywordflow">if</span> ((board&lt;1) || (board&gt;62)) {</div><div class="line"><a name="l00481"></a><span class="lineno">  481</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid board number %d :: board numbers must be between 1 and 62&quot;</span>, board);</div><div class="line"><a name="l00482"></a><span class="lineno">  482</span>&#160;        <span class="keywordflow">return</span>;</div><div class="line"><a name="l00483"></a><span class="lineno">  483</span>&#160;    }</div><div class="line"><a name="l00484"></a><span class="lineno">  484</span>&#160;    <span class="keywordflow">if</span> (_active_board != board) {</div><div class="line"><a name="l00485"></a><span class="lineno">  485</span>&#160;        _active_board = board;   <span class="comment">// save to global</span></div><div class="line"><a name="l00486"></a><span class="lineno">  486</span>&#160;        </div><div class="line"><a name="l00487"></a><span class="lineno">  487</span>&#160;        <span class="comment">// the public API is ONE based and hardware is ZERO based</span></div><div class="line"><a name="l00488"></a><span class="lineno">  488</span>&#160;        board--;</div><div class="line"><a name="l00489"></a><span class="lineno">  489</span>&#160;        </div><div class="line"><a name="l00490"></a><span class="lineno">  490</span>&#160;        <span class="keywordflow">if</span> (0 &gt; ioctl (_controller_io_handle, I2C_SLAVE, (_BASE_ADDR+(board)))) {</div><div class="line"><a name="l00491"></a><span class="lineno">  491</span>&#160;            ROS_FATAL (<span class="stringliteral">&quot;Failed to acquire bus access and/or talk to I2C slave at address 0x%02X&quot;</span>, (_BASE_ADDR+board));</div><div class="line"><a name="l00492"></a><span class="lineno">  492</span>&#160;            <span class="keywordflow">return</span>; <span class="comment">/* exit(1) */</span>   <span class="comment">/* additional ERROR HANDLING information is available with &#39;errno&#39; */</span></div><div class="line"><a name="l00493"></a><span class="lineno">  493</span>&#160;        }</div><div class="line"><a name="l00494"></a><span class="lineno">  494</span>&#160;</div><div class="line"><a name="l00495"></a><span class="lineno">  495</span>&#160;        <span class="keywordflow">if</span> (_pwm_boards[board]&lt;0) {</div><div class="line"><a name="l00496"></a><span class="lineno">  496</span>&#160;            _pwm_boards[board] = 1;</div><div class="line"><a name="l00497"></a><span class="lineno">  497</span>&#160;</div><div class="line"><a name="l00498"></a><span class="lineno">  498</span>&#160;            <span class="comment">/* this is guess but I believe the following needs to be done on each board only once */</span></div><div class="line"><a name="l00499"></a><span class="lineno">  499</span>&#160;</div><div class="line"><a name="l00500"></a><span class="lineno">  500</span>&#160;            <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __MODE2, __OUTDRV))</div><div class="line"><a name="l00501"></a><span class="lineno">  501</span>&#160;                ROS_ERROR (<span class="stringliteral">&quot;Failed to enable PWM outputs for totem-pole structure&quot;</span>);</div><div class="line"><a name="l00502"></a><span class="lineno">  502</span>&#160;</div><div class="line"><a name="l00503"></a><span class="lineno">  503</span>&#160;            <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __MODE1, __ALLCALL))</div><div class="line"><a name="l00504"></a><span class="lineno">  504</span>&#160;                ROS_ERROR (<span class="stringliteral">&quot;Failed to enable ALLCALL for PWM channels&quot;</span>);</div><div class="line"><a name="l00505"></a><span class="lineno">  505</span>&#160;</div><div class="line"><a name="l00506"></a><span class="lineno">  506</span>&#160;            nanosleep ((<span class="keyword">const</span> <span class="keyword">struct</span> timespec[]){{0, 5000000L}}, NULL);   <span class="comment">//sleep 5microsec, wait for osci</span></div><div class="line"><a name="l00507"></a><span class="lineno">  507</span>&#160;</div><div class="line"><a name="l00508"></a><span class="lineno">  508</span>&#160;</div><div class="line"><a name="l00509"></a><span class="lineno">  509</span>&#160;            mode1res = i2c_smbus_read_byte_data (_controller_io_handle, __MODE1);</div><div class="line"><a name="l00510"></a><span class="lineno">  510</span>&#160;            mode1res = mode1res &amp; ~__SLEEP; <span class="comment">//                 # wake up (reset sleep)</span></div><div class="line"><a name="l00511"></a><span class="lineno">  511</span>&#160;</div><div class="line"><a name="l00512"></a><span class="lineno">  512</span>&#160;            <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __MODE1, mode1res))</div><div class="line"><a name="l00513"></a><span class="lineno">  513</span>&#160;                ROS_ERROR (<span class="stringliteral">&quot;Failed to recover from low power mode&quot;</span>);</div><div class="line"><a name="l00514"></a><span class="lineno">  514</span>&#160;</div><div class="line"><a name="l00515"></a><span class="lineno">  515</span>&#160;            nanosleep((<span class="keyword">const</span> <span class="keyword">struct</span> timespec[]){{0, 5000000L}}, NULL);   <span class="comment">//sleep 5microsec, wait for osci</span></div><div class="line"><a name="l00516"></a><span class="lineno">  516</span>&#160;</div><div class="line"><a name="l00517"></a><span class="lineno">  517</span>&#160;            <span class="comment">// the first time we activate a board, we mark it and set all of its servo channels to 0</span></div><div class="line"><a name="l00518"></a><span class="lineno">  518</span>&#160;            _set_pwm_interval_all (0, 0);</div><div class="line"><a name="l00519"></a><span class="lineno">  519</span>&#160;        }</div><div class="line"><a name="l00520"></a><span class="lineno">  520</span>&#160;    }</div><div class="line"><a name="l00521"></a><span class="lineno">  521</span>&#160;}</div><div class="line"><a name="l00522"></a><span class="lineno">  522</span>&#160;</div><div class="line"><a name="l00523"></a><span class="lineno">  523</span>&#160;</div><div class="line"><a name="l00524"></a><span class="lineno">  524</span>&#160;</div><div class="line"><a name="l00534"></a><span class="lineno">  534</span>&#160;<span class="keyword">static</span> <span class="keywordtype">void</span> _set_pwm_interval (<span class="keywordtype">int</span> servo, <span class="keywordtype">int</span> start, <span class="keywordtype">int</span> end)</div><div class="line"><a name="l00535"></a><span class="lineno">  535</span>&#160;{</div><div class="line"><a name="l00536"></a><span class="lineno">  536</span>&#160;    ROS_DEBUG(<span class="stringliteral">&quot;_set_pwm_interval enter&quot;</span>);</div><div class="line"><a name="l00537"></a><span class="lineno">  537</span>&#160;</div><div class="line"><a name="l00538"></a><span class="lineno">  538</span>&#160;    <span class="keywordflow">if</span> ((servo&lt;1) || (servo&gt;(MAX_SERVOS))) {</div><div class="line"><a name="l00539"></a><span class="lineno">  539</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid servo number %d :: servo numbers must be between 1 and %d&quot;</span>, servo, MAX_BOARDS);</div><div class="line"><a name="l00540"></a><span class="lineno">  540</span>&#160;        <span class="keywordflow">return</span>;</div><div class="line"><a name="l00541"></a><span class="lineno">  541</span>&#160;    }</div><div class="line"><a name="l00542"></a><span class="lineno">  542</span>&#160;</div><div class="line"><a name="l00543"></a><span class="lineno">  543</span>&#160;    <span class="keywordtype">int</span> board = ((int)(servo/16))+1;</div><div class="line"><a name="l00544"></a><span class="lineno">  544</span>&#160;    _set_active_board(board);</div><div class="line"><a name="l00545"></a><span class="lineno">  545</span>&#160;</div><div class="line"><a name="l00546"></a><span class="lineno">  546</span>&#160;    servo = servo % 16;</div><div class="line"><a name="l00547"></a><span class="lineno">  547</span>&#160;</div><div class="line"><a name="l00548"></a><span class="lineno">  548</span>&#160;    board = _active_board - 1;</div><div class="line"><a name="l00549"></a><span class="lineno">  549</span>&#160;</div><div class="line"><a name="l00550"></a><span class="lineno">  550</span>&#160;    ROS_DEBUG(<span class="stringliteral">&quot;_set_pwm_interval board=%d&quot;</span>, board);</div><div class="line"><a name="l00551"></a><span class="lineno">  551</span>&#160;    <span class="comment">// the public API is ONE based and hardware is ZERO based</span></div><div class="line"><a name="l00552"></a><span class="lineno">  552</span>&#160;</div><div class="line"><a name="l00553"></a><span class="lineno">  553</span>&#160;    <span class="keywordtype">int</span> channel = servo - 1;</div><div class="line"><a name="l00554"></a><span class="lineno">  554</span>&#160;    </div><div class="line"><a name="l00555"></a><span class="lineno">  555</span>&#160;    <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __CHANNEL_ON_L+4*channel, start &amp; 0xFF))</div><div class="line"><a name="l00556"></a><span class="lineno">  556</span>&#160;        ROS_ERROR (<span class="stringliteral">&quot;Error setting PWM start low byte on servo %d on board %d&quot;</span>, servo, _active_board);</div><div class="line"><a name="l00557"></a><span class="lineno">  557</span>&#160;    <span class="keywordflow">if</span> (0 &gt;  i2c_smbus_write_byte_data (_controller_io_handle, __CHANNEL_ON_H+4*channel, start  &gt;&gt; 8))</div><div class="line"><a name="l00558"></a><span class="lineno">  558</span>&#160;        ROS_ERROR (<span class="stringliteral">&quot;Error setting PWM start high byte on servo %d on board %d&quot;</span>, servo, _active_board);</div><div class="line"><a name="l00559"></a><span class="lineno">  559</span>&#160;    <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __CHANNEL_OFF_L+4*channel, end &amp; 0xFF))</div><div class="line"><a name="l00560"></a><span class="lineno">  560</span>&#160;        ROS_ERROR (<span class="stringliteral">&quot;Error setting PWM end low byte on servo %d on board %d&quot;</span>, servo, _active_board);</div><div class="line"><a name="l00561"></a><span class="lineno">  561</span>&#160;    <span class="keywordflow">if</span> (0 &gt; i2c_smbus_write_byte_data (_controller_io_handle, __CHANNEL_OFF_H+4*channel, end &gt;&gt; 8))</div><div class="line"><a name="l00562"></a><span class="lineno">  562</span>&#160;        ROS_ERROR (<span class="stringliteral">&quot;Error setting PWM end high byte on servo %d on board %d&quot;</span>, servo, _active_board);</div><div class="line"><a name="l00563"></a><span class="lineno">  563</span>&#160;}</div><div class="line"><a name="l00564"></a><span class="lineno">  564</span>&#160;</div><div class="line"><a name="l00565"></a><span class="lineno">  565</span>&#160;</div><div class="line"><a name="l00566"></a><span class="lineno">  566</span>&#160;</div><div class="line"><a name="l00575"></a><span class="lineno">  575</span>&#160;<span class="keyword">static</span> <span class="keywordtype">void</span> _set_pwm_interval_proportional (<span class="keywordtype">int</span> servo, <span class="keywordtype">float</span> value)</div><div class="line"><a name="l00576"></a><span class="lineno">  576</span>&#160;{</div><div class="line"><a name="l00577"></a><span class="lineno">  577</span>&#160;    <span class="keywordflow">if</span> ((value &lt; -1.0) || (value &gt; 1.0)) {</div><div class="line"><a name="l00578"></a><span class="lineno">  578</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid proportion value %f :: proportion values must be between -1.0 and 1.0&quot;</span>, value);</div><div class="line"><a name="l00579"></a><span class="lineno">  579</span>&#160;        <span class="keywordflow">return</span>;</div><div class="line"><a name="l00580"></a><span class="lineno">  580</span>&#160;    }</div><div class="line"><a name="l00581"></a><span class="lineno">  581</span>&#160;</div><div class="line"><a name="l00582"></a><span class="lineno">  582</span>&#160;    servo_config* configp = &amp;(_servo_configs[servo-1]);</div><div class="line"><a name="l00583"></a><span class="lineno">  583</span>&#160;    </div><div class="line"><a name="l00584"></a><span class="lineno">  584</span>&#160;    <span class="keywordflow">if</span> ((configp-&gt;center &lt; 0) ||(configp-&gt;range &lt; 0)) {</div><div class="line"><a name="l00585"></a><span class="lineno">  585</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Missing servo configuration for servo[%d]&quot;</span>, servo);</div><div class="line"><a name="l00586"></a><span class="lineno">  586</span>&#160;        <span class="keywordflow">return</span>;</div><div class="line"><a name="l00587"></a><span class="lineno">  587</span>&#160;    }</div><div class="line"><a name="l00588"></a><span class="lineno">  588</span>&#160;</div><div class="line"><a name="l00589"></a><span class="lineno">  589</span>&#160;    <span class="keywordtype">int</span> pos = (configp-&gt;direction * (((float)(configp-&gt;range) / 2) * value)) + configp-&gt;center;</div><div class="line"><a name="l00590"></a><span class="lineno">  590</span>&#160;        </div><div class="line"><a name="l00591"></a><span class="lineno">  591</span>&#160;    if ((pos &lt; 0) || (pos &gt; 4096)) {</div><div class="line"><a name="l00592"></a><span class="lineno">  592</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid computed position servo[%d] = (direction(%d) * ((range(%d) / 2) * value(%6.4f))) + %d = %d&quot;</span>, servo, configp-&gt;direction, configp-&gt;range, value, configp-&gt;center, pos);</div><div class="line"><a name="l00593"></a><span class="lineno">  593</span>&#160;        <span class="keywordflow">return</span>;</div><div class="line"><a name="l00594"></a><span class="lineno">  594</span>&#160;    }</div><div class="line"><a name="l00595"></a><span class="lineno">  595</span>&#160;    _set_pwm_interval (servo, 0, pos);</div><div class="line"><a name="l00596"></a><span class="lineno">  596</span>&#160;    ROS_DEBUG(<span class="stringliteral">&quot;servo[%d] = (direction(%d) * ((range(%d) / 2) * value(%6.4f))) + %d = %d&quot;</span>, servo, configp-&gt;direction, configp-&gt;range, value, configp-&gt;center, pos);</div><div class="line"><a name="l00597"></a><span class="lineno">  597</span>&#160;}</div><div class="line"><a name="l00598"></a><span class="lineno">  598</span>&#160;</div><div class="line"><a name="l00599"></a><span class="lineno">  599</span>&#160;</div><div class="line"><a name="l00600"></a><span class="lineno">  600</span>&#160;</div><div class="line"><a name="l00610"></a><span class="lineno">  610</span>&#160;<span class="keyword">static</span> <span class="keywordtype">void</span> _config_servo (<span class="keywordtype">int</span> servo, <span class="keywordtype">int</span> center, <span class="keywordtype">int</span> range, <span class="keywordtype">int</span> direction)</div><div class="line"><a name="l00611"></a><span class="lineno">  611</span>&#160;{</div><div class="line"><a name="l00612"></a><span class="lineno">  612</span>&#160;    <span class="keywordflow">if</span> ((servo &lt; 1) || (servo &gt; (MAX_SERVOS))) {</div><div class="line"><a name="l00613"></a><span class="lineno">  613</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid servo number %d :: servo numbers must be between 1 and %d&quot;</span>, servo, MAX_SERVOS);</div><div class="line"><a name="l00614"></a><span class="lineno">  614</span>&#160;        <span class="keywordflow">return</span>;</div><div class="line"><a name="l00615"></a><span class="lineno">  615</span>&#160;    }</div><div class="line"><a name="l00616"></a><span class="lineno">  616</span>&#160;</div><div class="line"><a name="l00617"></a><span class="lineno">  617</span>&#160;    <span class="keywordflow">if</span> ((center &lt; 0) || (center &gt; 4096))</div><div class="line"><a name="l00618"></a><span class="lineno">  618</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid center value %d :: center values must be between 0 and 4096&quot;</span>, center);</div><div class="line"><a name="l00619"></a><span class="lineno">  619</span>&#160;</div><div class="line"><a name="l00620"></a><span class="lineno">  620</span>&#160;    <span class="keywordflow">if</span> ((center &lt; 0) || (center &gt; 4096))</div><div class="line"><a name="l00621"></a><span class="lineno">  621</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid range value %d :: range values must be between 0 and 4096&quot;</span>, range);</div><div class="line"><a name="l00622"></a><span class="lineno">  622</span>&#160;</div><div class="line"><a name="l00623"></a><span class="lineno">  623</span>&#160;    <span class="keywordflow">if</span> (((center - (range/2)) &lt; 0) || (((range/2) + center) &gt; 4096))</div><div class="line"><a name="l00624"></a><span class="lineno">  624</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid range center combination %d ± %d :: range/2 ± center must be between 0 and 4096&quot;</span>, center, (range/2));</div><div class="line"><a name="l00625"></a><span class="lineno">  625</span>&#160;</div><div class="line"><a name="l00626"></a><span class="lineno">  626</span>&#160;    _servo_configs[servo-1].center = center;</div><div class="line"><a name="l00627"></a><span class="lineno">  627</span>&#160;    _servo_configs[servo-1].range = range;</div><div class="line"><a name="l00628"></a><span class="lineno">  628</span>&#160;    _servo_configs[servo-1].direction = direction;</div><div class="line"><a name="l00629"></a><span class="lineno">  629</span>&#160;    _servo_configs[servo-1].mode_pos = POSITION_UNDEFINED;</div><div class="line"><a name="l00630"></a><span class="lineno">  630</span>&#160;</div><div class="line"><a name="l00631"></a><span class="lineno">  631</span>&#160;    <span class="keywordflow">if</span> (servo &gt; _last_servo)    <span class="comment">// used for internal optimizations</span></div><div class="line"><a name="l00632"></a><span class="lineno">  632</span>&#160;        _last_servo = servo;</div><div class="line"><a name="l00633"></a><span class="lineno">  633</span>&#160;</div><div class="line"><a name="l00634"></a><span class="lineno">  634</span>&#160;    ROS_INFO(<span class="stringliteral">&quot;Servo #%d configured: center=%d, range=%d, direction=%d&quot;</span>, servo, center, range, direction);</div><div class="line"><a name="l00635"></a><span class="lineno">  635</span>&#160;}</div><div class="line"><a name="l00636"></a><span class="lineno">  636</span>&#160;</div><div class="line"><a name="l00637"></a><span class="lineno">  637</span>&#160;</div><div class="line"><a name="l00638"></a><span class="lineno">  638</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _config_servo_position (<span class="keywordtype">int</span> servo, <span class="keywordtype">int</span> position)</div><div class="line"><a name="l00639"></a><span class="lineno">  639</span>&#160;{</div><div class="line"><a name="l00640"></a><span class="lineno">  640</span>&#160;    <span class="keywordflow">if</span> ((servo &lt; 1) || (servo &gt; (MAX_SERVOS))) {</div><div class="line"><a name="l00641"></a><span class="lineno">  641</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid servo number %d :: servo numbers must be between 1 and %d&quot;</span>, servo, MAX_SERVOS);</div><div class="line"><a name="l00642"></a><span class="lineno">  642</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00643"></a><span class="lineno">  643</span>&#160;    }</div><div class="line"><a name="l00644"></a><span class="lineno">  644</span>&#160;    <span class="keywordflow">if</span> ((position &lt; POSITION_UNDEFINED) || (position &gt; POSITION_RIGHTREAR)) {</div><div class="line"><a name="l00645"></a><span class="lineno">  645</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid drive mode position %d :: positions are 0 = non-drive, 1 = left front, 2 = right front, 3 = left rear, and 4 = right rear&quot;</span>, position);</div><div class="line"><a name="l00646"></a><span class="lineno">  646</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00647"></a><span class="lineno">  647</span>&#160;    }</div><div class="line"><a name="l00648"></a><span class="lineno">  648</span>&#160;    _servo_configs[servo-1].mode_pos = position;</div><div class="line"><a name="l00649"></a><span class="lineno">  649</span>&#160;    ROS_INFO(<span class="stringliteral">&quot;Servo #%d configured: position=%d&quot;</span>, servo, position);</div><div class="line"><a name="l00650"></a><span class="lineno">  650</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00651"></a><span class="lineno">  651</span>&#160;}</div><div class="line"><a name="l00652"></a><span class="lineno">  652</span>&#160;</div><div class="line"><a name="l00653"></a><span class="lineno">  653</span>&#160;</div><div class="line"><a name="l00654"></a><span class="lineno">  654</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _config_drive_mode (std::string mode, <span class="keywordtype">float</span> rpm, <span class="keywordtype">float</span> radius, <span class="keywordtype">float</span> track, <span class="keywordtype">float</span> scale)</div><div class="line"><a name="l00655"></a><span class="lineno">  655</span>&#160;{</div><div class="line"><a name="l00656"></a><span class="lineno">  656</span>&#160;    <span class="keywordtype">int</span> mode_val = MODE_UNDEFINED;</div><div class="line"><a name="l00657"></a><span class="lineno">  657</span>&#160;</div><div class="line"><a name="l00658"></a><span class="lineno">  658</span>&#160;    <span class="comment">// assumes the parameter was provided in the proper case</span></div><div class="line"><a name="l00659"></a><span class="lineno">  659</span>&#160;    <span class="keywordflow">if</span>      (0 == strcmp (mode.c_str(), _CONST(<span class="stringliteral">&quot;ackerman&quot;</span>)))</div><div class="line"><a name="l00660"></a><span class="lineno">  660</span>&#160;        mode_val = MODE_ACKERMAN;</div><div class="line"><a name="l00661"></a><span class="lineno">  661</span>&#160;    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (0 == strcmp (mode.c_str(), _CONST(<span class="stringliteral">&quot;differential&quot;</span>)))</div><div class="line"><a name="l00662"></a><span class="lineno">  662</span>&#160;        mode_val = MODE_DIFFERENTIAL;</div><div class="line"><a name="l00663"></a><span class="lineno">  663</span>&#160;    <span class="keywordflow">else</span> <span class="keywordflow">if</span> (0 == strcmp (mode.c_str(), _CONST(<span class="stringliteral">&quot;mecanum&quot;</span>)))</div><div class="line"><a name="l00664"></a><span class="lineno">  664</span>&#160;        mode_val = MODE_MECANUM;</div><div class="line"><a name="l00665"></a><span class="lineno">  665</span>&#160;    <span class="keywordflow">else</span> {</div><div class="line"><a name="l00666"></a><span class="lineno">  666</span>&#160;        mode_val = MODE_INVALID;</div><div class="line"><a name="l00667"></a><span class="lineno">  667</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid drive mode %s :: drive mode must be one of ackerman, differential, or mecanum&quot;</span>, mode.c_str());</div><div class="line"><a name="l00668"></a><span class="lineno">  668</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00669"></a><span class="lineno">  669</span>&#160;    }</div><div class="line"><a name="l00670"></a><span class="lineno">  670</span>&#160;</div><div class="line"><a name="l00671"></a><span class="lineno">  671</span>&#160;    <span class="keywordflow">if</span> (rpm &lt;= 0.0) {</div><div class="line"><a name="l00672"></a><span class="lineno">  672</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid RPM %6.4f :: the motor&#39;s output RPM must be greater than 0.0&quot;</span>, rpm);</div><div class="line"><a name="l00673"></a><span class="lineno">  673</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00674"></a><span class="lineno">  674</span>&#160;    }</div><div class="line"><a name="l00675"></a><span class="lineno">  675</span>&#160;</div><div class="line"><a name="l00676"></a><span class="lineno">  676</span>&#160;    <span class="keywordflow">if</span> (radius &lt;= 0.0) {</div><div class="line"><a name="l00677"></a><span class="lineno">  677</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid radius %6.4f :: the wheel radius must be greater than 0.0 meters&quot;</span>, radius);</div><div class="line"><a name="l00678"></a><span class="lineno">  678</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00679"></a><span class="lineno">  679</span>&#160;    }</div><div class="line"><a name="l00680"></a><span class="lineno">  680</span>&#160;</div><div class="line"><a name="l00681"></a><span class="lineno">  681</span>&#160;    <span class="keywordflow">if</span> (track &lt;= 0.0) {</div><div class="line"><a name="l00682"></a><span class="lineno">  682</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid track %6.4f :: the axel track must be greater than 0.0 meters&quot;</span>, track);</div><div class="line"><a name="l00683"></a><span class="lineno">  683</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00684"></a><span class="lineno">  684</span>&#160;    }</div><div class="line"><a name="l00685"></a><span class="lineno">  685</span>&#160;</div><div class="line"><a name="l00686"></a><span class="lineno">  686</span>&#160;    <span class="keywordflow">if</span> (scale &lt;= 0.0) {</div><div class="line"><a name="l00687"></a><span class="lineno">  687</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid scale %6.4f :: the scalar for Twist messages must be greater than 0.0&quot;</span>, scale);</div><div class="line"><a name="l00688"></a><span class="lineno">  688</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00689"></a><span class="lineno">  689</span>&#160;    }</div><div class="line"><a name="l00690"></a><span class="lineno">  690</span>&#160;</div><div class="line"><a name="l00691"></a><span class="lineno">  691</span>&#160;    _active_drive.mode = mode_val;</div><div class="line"><a name="l00692"></a><span class="lineno">  692</span>&#160;    _active_drive.rpm = rpm;</div><div class="line"><a name="l00693"></a><span class="lineno">  693</span>&#160;    _active_drive.radius = radius;  <span class="comment">// the service takes the radius in meters</span></div><div class="line"><a name="l00694"></a><span class="lineno">  694</span>&#160;    _active_drive.track = track;        <span class="comment">// the service takes the track in meters</span></div><div class="line"><a name="l00695"></a><span class="lineno">  695</span>&#160;    _active_drive.scale = scale;</div><div class="line"><a name="l00696"></a><span class="lineno">  696</span>&#160;</div><div class="line"><a name="l00697"></a><span class="lineno">  697</span>&#160;    ROS_INFO(<span class="stringliteral">&quot;Drive mode configured: mode=%s, rpm=%6.4f, radius=%6.4f, track=%6.4f, scale=%6.4f&quot;</span>, mode.c_str(), rpm, radius, track, scale);</div><div class="line"><a name="l00698"></a><span class="lineno">  698</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00699"></a><span class="lineno">  699</span>&#160;}</div><div class="line"><a name="l00700"></a><span class="lineno">  700</span>&#160;</div><div class="line"><a name="l00701"></a><span class="lineno">  701</span>&#160;</div><div class="line"><a name="l00702"></a><span class="lineno">  702</span>&#160;</div><div class="line"><a name="l00710"></a><span class="lineno">  710</span>&#160;<span class="keyword">static</span> <span class="keywordtype">void</span> _init (<span class="keywordtype">char</span>* filename)</div><div class="line"><a name="l00711"></a><span class="lineno">  711</span>&#160;{</div><div class="line"><a name="l00712"></a><span class="lineno">  712</span>&#160;    <span class="keywordtype">int</span> res;</div><div class="line"><a name="l00713"></a><span class="lineno">  713</span>&#160;    <span class="keywordtype">char</span> mode1res;</div><div class="line"><a name="l00714"></a><span class="lineno">  714</span>&#160;    <span class="keywordtype">int</span> i;</div><div class="line"><a name="l00715"></a><span class="lineno">  715</span>&#160;</div><div class="line"><a name="l00716"></a><span class="lineno">  716</span>&#160;    <span class="comment">/* initialize all of the global data objects */</span></div><div class="line"><a name="l00717"></a><span class="lineno">  717</span>&#160;    </div><div class="line"><a name="l00718"></a><span class="lineno">  718</span>&#160;    <span class="keywordflow">for</span> (i=0; i&lt;MAX_BOARDS;i++)</div><div class="line"><a name="l00719"></a><span class="lineno">  719</span>&#160;        _pwm_boards[i] = -1;</div><div class="line"><a name="l00720"></a><span class="lineno">  720</span>&#160;    _active_board = -1;</div><div class="line"><a name="l00721"></a><span class="lineno">  721</span>&#160;</div><div class="line"><a name="l00722"></a><span class="lineno">  722</span>&#160;    <span class="keywordflow">for</span> (i=0; i&lt;(MAX_SERVOS);i++) {</div><div class="line"><a name="l00723"></a><span class="lineno">  723</span>&#160;        <span class="comment">// these values have not useful meaning</span></div><div class="line"><a name="l00724"></a><span class="lineno">  724</span>&#160;        _servo_configs[i].center = -1;</div><div class="line"><a name="l00725"></a><span class="lineno">  725</span>&#160;        _servo_configs[i].range = -1;</div><div class="line"><a name="l00726"></a><span class="lineno">  726</span>&#160;        _servo_configs[i].direction = 1;</div><div class="line"><a name="l00727"></a><span class="lineno">  727</span>&#160;        _servo_configs[i].mode_pos = -1;</div><div class="line"><a name="l00728"></a><span class="lineno">  728</span>&#160;    }</div><div class="line"><a name="l00729"></a><span class="lineno">  729</span>&#160;    _last_servo = -1;</div><div class="line"><a name="l00730"></a><span class="lineno">  730</span>&#160;</div><div class="line"><a name="l00731"></a><span class="lineno">  731</span>&#160;    _active_drive.mode = MODE_UNDEFINED;</div><div class="line"><a name="l00732"></a><span class="lineno">  732</span>&#160;    _active_drive.rpm = -1.0;</div><div class="line"><a name="l00733"></a><span class="lineno">  733</span>&#160;    _active_drive.radius = -1.0;</div><div class="line"><a name="l00734"></a><span class="lineno">  734</span>&#160;    _active_drive.track = -1.0;</div><div class="line"><a name="l00735"></a><span class="lineno">  735</span>&#160;    _active_drive.scale = -1.0;</div><div class="line"><a name="l00736"></a><span class="lineno">  736</span>&#160;    </div><div class="line"><a name="l00737"></a><span class="lineno">  737</span>&#160;    </div><div class="line"><a name="l00738"></a><span class="lineno">  738</span>&#160;    <span class="keywordflow">if</span> ((_controller_io_handle = open (filename, O_RDWR)) &lt; 0) {</div><div class="line"><a name="l00739"></a><span class="lineno">  739</span>&#160;        ROS_FATAL (<span class="stringliteral">&quot;Failed to open I2C bus %s&quot;</span>, filename);</div><div class="line"><a name="l00740"></a><span class="lineno">  740</span>&#160;        <span class="keywordflow">return</span>; <span class="comment">/* exit(1) */</span>   <span class="comment">/* additional ERROR HANDLING information is available with &#39;errno&#39; */</span></div><div class="line"><a name="l00741"></a><span class="lineno">  741</span>&#160;    }</div><div class="line"><a name="l00742"></a><span class="lineno">  742</span>&#160;}</div><div class="line"><a name="l00743"></a><span class="lineno">  743</span>&#160;</div><div class="line"><a name="l00744"></a><span class="lineno">  744</span>&#160;</div><div class="line"><a name="l00745"></a><span class="lineno">  745</span>&#160;</div><div class="line"><a name="l00746"></a><span class="lineno">  746</span>&#160;<span class="comment">// ------------------------------------------------------------------------------------------------------------------------------------</span></div><div class="line"><a name="l00750"></a><span class="lineno">  750</span>&#160;<span class="comment"></span><span class="comment">// ------------------------------------------------------------------------------------------------------------------------------------</span></div><div class="line"><a name="l00751"></a><span class="lineno">  751</span>&#160;</div><div class="line"><a name="l00797"></a><span class="lineno"><a class="line" href="group___topics.html#gaa3fe8c6f5a98243c302c0d27cea219d9">  797</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="group___topics.html#gaa3fe8c6f5a98243c302c0d27cea219d9">servos_absolute</a> (<span class="keyword">const</span> i2cpwm_board::ServoArray::ConstPtr&amp; msg)</div><div class="line"><a name="l00798"></a><span class="lineno">  798</span>&#160;{</div><div class="line"><a name="l00799"></a><span class="lineno">  799</span>&#160;    <span class="comment">/* this subscription works on the active_board */</span></div><div class="line"><a name="l00800"></a><span class="lineno">  800</span>&#160;    </div><div class="line"><a name="l00801"></a><span class="lineno">  801</span>&#160;    <span class="keywordflow">for</span>(std::vector&lt;i2cpwm_board::Servo&gt;::const_iterator sp = msg-&gt;servos.begin(); sp != msg-&gt;servos.end(); ++sp) {</div><div class="line"><a name="l00802"></a><span class="lineno">  802</span>&#160;        <span class="keywordtype">int</span> servo = sp-&gt;servo;</div><div class="line"><a name="l00803"></a><span class="lineno">  803</span>&#160;        <span class="keywordtype">int</span> value = sp-&gt;value;</div><div class="line"><a name="l00804"></a><span class="lineno">  804</span>&#160;</div><div class="line"><a name="l00805"></a><span class="lineno">  805</span>&#160;        <span class="keywordflow">if</span> ((value &lt; 0) || (value &gt; 4096)) {</div><div class="line"><a name="l00806"></a><span class="lineno">  806</span>&#160;            ROS_ERROR(<span class="stringliteral">&quot;Invalid PWM value %d :: PWM values must be between 0 and 4096&quot;</span>, value);</div><div class="line"><a name="l00807"></a><span class="lineno">  807</span>&#160;            <span class="keywordflow">continue</span>;</div><div class="line"><a name="l00808"></a><span class="lineno">  808</span>&#160;        }</div><div class="line"><a name="l00809"></a><span class="lineno">  809</span>&#160;        _set_pwm_interval (servo, 0, value);</div><div class="line"><a name="l00810"></a><span class="lineno">  810</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;servo[%d] = %d&quot;</span>, servo, value);</div><div class="line"><a name="l00811"></a><span class="lineno">  811</span>&#160;    }</div><div class="line"><a name="l00812"></a><span class="lineno">  812</span>&#160;}</div><div class="line"><a name="l00813"></a><span class="lineno">  813</span>&#160;</div><div class="line"><a name="l00814"></a><span class="lineno">  814</span>&#160;</div><div class="line"><a name="l00867"></a><span class="lineno"><a class="line" href="group___topics.html#ga1262b2e51072c237c51b6de4cb199e53">  867</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="group___topics.html#ga1262b2e51072c237c51b6de4cb199e53">servos_proportional</a> (<span class="keyword">const</span> i2cpwm_board::ServoArray::ConstPtr&amp; msg)</div><div class="line"><a name="l00868"></a><span class="lineno">  868</span>&#160;{</div><div class="line"><a name="l00869"></a><span class="lineno">  869</span>&#160;    <span class="comment">/* this subscription works on the active_board */</span></div><div class="line"><a name="l00870"></a><span class="lineno">  870</span>&#160;</div><div class="line"><a name="l00871"></a><span class="lineno">  871</span>&#160;    <span class="keywordflow">for</span>(std::vector&lt;i2cpwm_board::Servo&gt;::const_iterator sp = msg-&gt;servos.begin(); sp != msg-&gt;servos.end(); ++sp) {</div><div class="line"><a name="l00872"></a><span class="lineno">  872</span>&#160;        <span class="keywordtype">int</span> servo = sp-&gt;servo;</div><div class="line"><a name="l00873"></a><span class="lineno">  873</span>&#160;        <span class="keywordtype">float</span> value = sp-&gt;value;</div><div class="line"><a name="l00874"></a><span class="lineno">  874</span>&#160;        _set_pwm_interval_proportional (servo, value);</div><div class="line"><a name="l00875"></a><span class="lineno">  875</span>&#160;    }</div><div class="line"><a name="l00876"></a><span class="lineno">  876</span>&#160;}</div><div class="line"><a name="l00877"></a><span class="lineno">  877</span>&#160;</div><div class="line"><a name="l00878"></a><span class="lineno">  878</span>&#160;</div><div class="line"><a name="l00879"></a><span class="lineno">  879</span>&#160;</div><div class="line"><a name="l00880"></a><span class="lineno">  880</span>&#160;</div><div class="line"><a name="l00976"></a><span class="lineno"><a class="line" href="group___topics.html#gae257665eb64139d2720ed332e61507c6">  976</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="group___topics.html#gae257665eb64139d2720ed332e61507c6">servos_drive</a> (<span class="keyword">const</span> geometry_msgs::Twist::ConstPtr&amp; msg)</div><div class="line"><a name="l00977"></a><span class="lineno">  977</span>&#160;{</div><div class="line"><a name="l00978"></a><span class="lineno">  978</span>&#160;    <span class="comment">/* this subscription works on the active_board */</span></div><div class="line"><a name="l00979"></a><span class="lineno">  979</span>&#160;</div><div class="line"><a name="l00980"></a><span class="lineno">  980</span>&#160;    <span class="keywordtype">int</span> i;</div><div class="line"><a name="l00981"></a><span class="lineno">  981</span>&#160;    <span class="keywordtype">float</span> delta, range, ratio;</div><div class="line"><a name="l00982"></a><span class="lineno">  982</span>&#160;    <span class="keywordtype">float</span> temp_x, temp_y, temp_r;</div><div class="line"><a name="l00983"></a><span class="lineno">  983</span>&#160;    <span class="keywordtype">float</span> dir_x, dir_y, dir_r;</div><div class="line"><a name="l00984"></a><span class="lineno">  984</span>&#160;    <span class="keywordtype">float</span> speed[4];</div><div class="line"><a name="l00985"></a><span class="lineno">  985</span>&#160;    </div><div class="line"><a name="l00986"></a><span class="lineno">  986</span>&#160;    <span class="comment">/* msg is a pointer to a Twist message: msg-&gt;linear and msg-&gt;angular each of which have members .x .y .z */</span></div><div class="line"><a name="l00987"></a><span class="lineno">  987</span>&#160;    <span class="comment">/* the subscriber uses the maths from: http://robotsforroboticists.com/drive-kinematics/ */</span> </div><div class="line"><a name="l00988"></a><span class="lineno">  988</span>&#160;</div><div class="line"><a name="l00989"></a><span class="lineno">  989</span>&#160;    ROS_DEBUG(<span class="stringliteral">&quot;servos_drive Twist = [%5.2f %5.2f %5.2f] [%5.2f %5.2f %5.2f]&quot;</span>, </div><div class="line"><a name="l00990"></a><span class="lineno">  990</span>&#160;             msg-&gt;linear.x, msg-&gt;linear.y, msg-&gt;linear.z, msg-&gt;angular.x, msg-&gt;angular.y, msg-&gt;angular.z);</div><div class="line"><a name="l00991"></a><span class="lineno">  991</span>&#160;</div><div class="line"><a name="l00992"></a><span class="lineno">  992</span>&#160;    <span class="keywordflow">if</span> (_active_drive.mode == MODE_UNDEFINED) {</div><div class="line"><a name="l00993"></a><span class="lineno">  993</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;drive mode not set&quot;</span>);</div><div class="line"><a name="l00994"></a><span class="lineno">  994</span>&#160;        <span class="keywordflow">return</span>;</div><div class="line"><a name="l00995"></a><span class="lineno">  995</span>&#160;    }</div><div class="line"><a name="l00996"></a><span class="lineno">  996</span>&#160;    <span class="keywordflow">if</span> ((_active_drive.mode &lt; MODE_UNDEFINED) || (_active_drive.mode &gt;= MODE_INVALID)) {</div><div class="line"><a name="l00997"></a><span class="lineno">  997</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;unrecognized drive mode set %d&quot;</span>, _active_drive.mode);</div><div class="line"><a name="l00998"></a><span class="lineno">  998</span>&#160;        <span class="keywordflow">return</span>;</div><div class="line"><a name="l00999"></a><span class="lineno">  999</span>&#160;    }</div><div class="line"><a name="l01000"></a><span class="lineno"> 1000</span>&#160;</div><div class="line"><a name="l01001"></a><span class="lineno"> 1001</span>&#160;    dir_x = ((msg-&gt;linear.x  &lt; 0) ? -1 : 1);</div><div class="line"><a name="l01002"></a><span class="lineno"> 1002</span>&#160;    dir_y = ((msg-&gt;linear.y  &lt; 0) ? -1 : 1);</div><div class="line"><a name="l01003"></a><span class="lineno"> 1003</span>&#160;    dir_r = ((msg-&gt;angular.z &lt; 0) ? -1 : 1);</div><div class="line"><a name="l01004"></a><span class="lineno"> 1004</span>&#160;</div><div class="line"><a name="l01005"></a><span class="lineno"> 1005</span>&#160;    temp_x = _active_drive.scale * _abs(msg-&gt;linear.x);</div><div class="line"><a name="l01006"></a><span class="lineno"> 1006</span>&#160;    temp_y = _active_drive.scale * _abs(msg-&gt;linear.y);</div><div class="line"><a name="l01007"></a><span class="lineno"> 1007</span>&#160;    temp_r = _abs(msg-&gt;angular.z);</div><div class="line"><a name="l01008"></a><span class="lineno"> 1008</span>&#160;        </div><div class="line"><a name="l01009"></a><span class="lineno"> 1009</span>&#160;    <span class="comment">// temp_x = _smoothing (temp_x);</span></div><div class="line"><a name="l01010"></a><span class="lineno"> 1010</span>&#160;    <span class="comment">// temp_y = _smoothing (temp_y);</span></div><div class="line"><a name="l01011"></a><span class="lineno"> 1011</span>&#160;    <span class="comment">// temp_r = _smoothing (temp_r) / 2;</span></div><div class="line"><a name="l01012"></a><span class="lineno"> 1012</span>&#160;</div><div class="line"><a name="l01013"></a><span class="lineno"> 1013</span>&#160;    <span class="comment">/* the delta is the angular velocity * half the drive track */</span></div><div class="line"><a name="l01014"></a><span class="lineno"> 1014</span>&#160;    delta = (temp_r * (_active_drive.track / 2));</div><div class="line"><a name="l01015"></a><span class="lineno"> 1015</span>&#160;</div><div class="line"><a name="l01016"></a><span class="lineno"> 1016</span>&#160;    ratio = _convert_mps_to_proportional(temp_y + delta);</div><div class="line"><a name="l01017"></a><span class="lineno"> 1017</span>&#160;    <span class="keywordflow">if</span> (ratio &gt; 1.0)</div><div class="line"><a name="l01018"></a><span class="lineno"> 1018</span>&#160;        temp_y /= ratio;</div><div class="line"><a name="l01019"></a><span class="lineno"> 1019</span>&#160;</div><div class="line"><a name="l01020"></a><span class="lineno"> 1020</span>&#160;    </div><div class="line"><a name="l01021"></a><span class="lineno"> 1021</span>&#160;    <span class="keywordflow">switch</span> (_active_drive.mode) {</div><div class="line"><a name="l01022"></a><span class="lineno"> 1022</span>&#160;</div><div class="line"><a name="l01023"></a><span class="lineno"> 1023</span>&#160;    <span class="keywordflow">case</span> MODE_ACKERMAN:</div><div class="line"><a name="l01024"></a><span class="lineno"> 1024</span>&#160;        <span class="comment">/*</span></div><div class="line"><a name="l01025"></a><span class="lineno"> 1025</span>&#160;<span class="comment">          with ackerman drive, steering is handled by a separate servo</span></div><div class="line"><a name="l01026"></a><span class="lineno"> 1026</span>&#160;<span class="comment">          we drive assigned servos exclusively by the linear.x</span></div><div class="line"><a name="l01027"></a><span class="lineno"> 1027</span>&#160;<span class="comment">        */</span></div><div class="line"><a name="l01028"></a><span class="lineno"> 1028</span>&#160;        speed[0] = temp_x * dir_x;</div><div class="line"><a name="l01029"></a><span class="lineno"> 1029</span>&#160;        speed[0] = _convert_mps_to_proportional(speed[0]);</div><div class="line"><a name="l01030"></a><span class="lineno"> 1030</span>&#160;        <span class="keywordflow">if</span> (_abs(speed[0]) &gt; 1.0)</div><div class="line"><a name="l01031"></a><span class="lineno"> 1031</span>&#160;            speed[0] = 1.0 * dir_x;</div><div class="line"><a name="l01032"></a><span class="lineno"> 1032</span>&#160;        </div><div class="line"><a name="l01033"></a><span class="lineno"> 1033</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;ackerman drive mode speed=%6.4f&quot;</span>, speed[0]);</div><div class="line"><a name="l01034"></a><span class="lineno"> 1034</span>&#160;        <span class="keywordflow">break</span>;</div><div class="line"><a name="l01035"></a><span class="lineno"> 1035</span>&#160;</div><div class="line"><a name="l01036"></a><span class="lineno"> 1036</span>&#160;    <span class="keywordflow">case</span> MODE_DIFFERENTIAL:</div><div class="line"><a name="l01037"></a><span class="lineno"> 1037</span>&#160;        <span class="comment">/*</span></div><div class="line"><a name="l01038"></a><span class="lineno"> 1038</span>&#160;<span class="comment">          with differential drive, steering is handled by the relative speed of left and right servos</span></div><div class="line"><a name="l01039"></a><span class="lineno"> 1039</span>&#160;<span class="comment">          we drive assigned servos by mixing linear.x and angular.z</span></div><div class="line"><a name="l01040"></a><span class="lineno"> 1040</span>&#160;<span class="comment">          we compute the delta for left and right components</span></div><div class="line"><a name="l01041"></a><span class="lineno"> 1041</span>&#160;<span class="comment">          we use the sign of the angular velocity to determine which is the faster / slower</span></div><div class="line"><a name="l01042"></a><span class="lineno"> 1042</span>&#160;<span class="comment">        */</span></div><div class="line"><a name="l01043"></a><span class="lineno"> 1043</span>&#160;</div><div class="line"><a name="l01044"></a><span class="lineno"> 1044</span>&#160;        <span class="comment">/* the delta is the angular velocity * half the drive track */</span></div><div class="line"><a name="l01045"></a><span class="lineno"> 1045</span>&#160;        </div><div class="line"><a name="l01046"></a><span class="lineno"> 1046</span>&#160;        <span class="keywordflow">if</span> (dir_r &gt; 0) {    <span class="comment">// turning right</span></div><div class="line"><a name="l01047"></a><span class="lineno"> 1047</span>&#160;            speed[0] = (temp_y + delta) * dir_y;</div><div class="line"><a name="l01048"></a><span class="lineno"> 1048</span>&#160;            speed[1] = (temp_y - delta) * dir_y;</div><div class="line"><a name="l01049"></a><span class="lineno"> 1049</span>&#160;        } <span class="keywordflow">else</span> {        <span class="comment">// turning left</span></div><div class="line"><a name="l01050"></a><span class="lineno"> 1050</span>&#160;            speed[0] = (temp_y - delta) * dir_y;</div><div class="line"><a name="l01051"></a><span class="lineno"> 1051</span>&#160;            speed[1] = (temp_y + delta) * dir_y;</div><div class="line"><a name="l01052"></a><span class="lineno"> 1052</span>&#160;        }</div><div class="line"><a name="l01053"></a><span class="lineno"> 1053</span>&#160;</div><div class="line"><a name="l01054"></a><span class="lineno"> 1054</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;computed differential drive mode speed left=%6.4f right=%6.4f&quot;</span>, speed[0], speed[1]);</div><div class="line"><a name="l01055"></a><span class="lineno"> 1055</span>&#160;</div><div class="line"><a name="l01056"></a><span class="lineno"> 1056</span>&#160;        <span class="comment">/* if any of the results are greater that 1.0, we need to scale all the results down */</span></div><div class="line"><a name="l01057"></a><span class="lineno"> 1057</span>&#160;        range = _max (_abs(speed[0]), _abs(speed[1]));</div><div class="line"><a name="l01058"></a><span class="lineno"> 1058</span>&#160;        </div><div class="line"><a name="l01059"></a><span class="lineno"> 1059</span>&#160;        ratio = _convert_mps_to_proportional(range);</div><div class="line"><a name="l01060"></a><span class="lineno"> 1060</span>&#160;        <span class="keywordflow">if</span> (ratio &gt; 1.0) {</div><div class="line"><a name="l01061"></a><span class="lineno"> 1061</span>&#160;            speed[0] /= ratio;</div><div class="line"><a name="l01062"></a><span class="lineno"> 1062</span>&#160;            speed[1] /= ratio;</div><div class="line"><a name="l01063"></a><span class="lineno"> 1063</span>&#160;        }</div><div class="line"><a name="l01064"></a><span class="lineno"> 1064</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;adjusted differential drive mode speed left=%6.4f right=%6.4f&quot;</span>, speed[0], speed[1]);</div><div class="line"><a name="l01065"></a><span class="lineno"> 1065</span>&#160;</div><div class="line"><a name="l01066"></a><span class="lineno"> 1066</span>&#160;        speed[0] = _convert_mps_to_proportional(speed[0]);</div><div class="line"><a name="l01067"></a><span class="lineno"> 1067</span>&#160;        speed[1] = _convert_mps_to_proportional(speed[1]);</div><div class="line"><a name="l01068"></a><span class="lineno"> 1068</span>&#160;</div><div class="line"><a name="l01069"></a><span class="lineno"> 1069</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;differential drive mode speed left=%6.4f right=%6.4f&quot;</span>, speed[0], speed[1]);</div><div class="line"><a name="l01070"></a><span class="lineno"> 1070</span>&#160;        <span class="keywordflow">break</span>;</div><div class="line"><a name="l01071"></a><span class="lineno"> 1071</span>&#160;</div><div class="line"><a name="l01072"></a><span class="lineno"> 1072</span>&#160;    <span class="keywordflow">case</span> MODE_MECANUM:</div><div class="line"><a name="l01073"></a><span class="lineno"> 1073</span>&#160;        <span class="comment">/*</span></div><div class="line"><a name="l01074"></a><span class="lineno"> 1074</span>&#160;<span class="comment">          with mecanum drive, steering is handled by the relative speed of left and right servos</span></div><div class="line"><a name="l01075"></a><span class="lineno"> 1075</span>&#160;<span class="comment">          with mecanum drive, lateral motion is handled by the rotation of front and rear servos</span></div><div class="line"><a name="l01076"></a><span class="lineno"> 1076</span>&#160;<span class="comment">          we drive assigned servos by mixing linear.x and angular.z  and linear.y</span></div><div class="line"><a name="l01077"></a><span class="lineno"> 1077</span>&#160;<span class="comment">        */</span></div><div class="line"><a name="l01078"></a><span class="lineno"> 1078</span>&#160;</div><div class="line"><a name="l01079"></a><span class="lineno"> 1079</span>&#160;        <span class="keywordflow">if</span> (dir_r &gt; 0) {    <span class="comment">// turning right</span></div><div class="line"><a name="l01080"></a><span class="lineno"> 1080</span>&#160;            speed[0] = speed[2] = (temp_y + delta) * dir_y;</div><div class="line"><a name="l01081"></a><span class="lineno"> 1081</span>&#160;            speed[1] = speed[3] = (temp_y - delta) * dir_y;</div><div class="line"><a name="l01082"></a><span class="lineno"> 1082</span>&#160;        } <span class="keywordflow">else</span> {        <span class="comment">// turning left</span></div><div class="line"><a name="l01083"></a><span class="lineno"> 1083</span>&#160;            speed[0] = speed[2] = (temp_y - delta) * dir_y;</div><div class="line"><a name="l01084"></a><span class="lineno"> 1084</span>&#160;            speed[1] = speed[3] = (temp_y + delta) * dir_y;</div><div class="line"><a name="l01085"></a><span class="lineno"> 1085</span>&#160;        }</div><div class="line"><a name="l01086"></a><span class="lineno"> 1086</span>&#160;</div><div class="line"><a name="l01087"></a><span class="lineno"> 1087</span>&#160;        speed[0] += temp_x * dir_x;</div><div class="line"><a name="l01088"></a><span class="lineno"> 1088</span>&#160;        speed[3] += temp_x * dir_x;</div><div class="line"><a name="l01089"></a><span class="lineno"> 1089</span>&#160;        speed[1] -= temp_x * dir_x;</div><div class="line"><a name="l01090"></a><span class="lineno"> 1090</span>&#160;        speed[2] -= temp_x * dir_x;</div><div class="line"><a name="l01091"></a><span class="lineno"> 1091</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;computed mecanum drive mode speed leftfront=%6.4f rightfront=%6.4f leftrear=%6.4f rightreer=%6.4f&quot;</span>, speed[0], speed[1], speed[2], speed[3]);</div><div class="line"><a name="l01092"></a><span class="lineno"> 1092</span>&#160;</div><div class="line"><a name="l01093"></a><span class="lineno"> 1093</span>&#160;        range = _max (_max (_max (_abs(speed[0]), _abs(speed[1])), _abs(speed[2])), _abs(speed[3]));</div><div class="line"><a name="l01094"></a><span class="lineno"> 1094</span>&#160;        ratio = _convert_mps_to_proportional(range);</div><div class="line"><a name="l01095"></a><span class="lineno"> 1095</span>&#160;        <span class="keywordflow">if</span> (ratio &gt; 1.0) {</div><div class="line"><a name="l01096"></a><span class="lineno"> 1096</span>&#160;            speed[0] /= ratio;</div><div class="line"><a name="l01097"></a><span class="lineno"> 1097</span>&#160;            speed[1] /= ratio;</div><div class="line"><a name="l01098"></a><span class="lineno"> 1098</span>&#160;            speed[2] /= ratio;</div><div class="line"><a name="l01099"></a><span class="lineno"> 1099</span>&#160;            speed[3] /= ratio;</div><div class="line"><a name="l01100"></a><span class="lineno"> 1100</span>&#160;        }</div><div class="line"><a name="l01101"></a><span class="lineno"> 1101</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;adjusted mecanum drive mode speed leftfront=%6.4f rightfront=%6.4f leftrear=%6.4f rightreer=%6.4f&quot;</span>, speed[0], speed[1], speed[2], speed[3]);</div><div class="line"><a name="l01102"></a><span class="lineno"> 1102</span>&#160;</div><div class="line"><a name="l01103"></a><span class="lineno"> 1103</span>&#160;        speed[0] = _convert_mps_to_proportional(speed[0]);</div><div class="line"><a name="l01104"></a><span class="lineno"> 1104</span>&#160;        speed[1] = _convert_mps_to_proportional(speed[1]);</div><div class="line"><a name="l01105"></a><span class="lineno"> 1105</span>&#160;        speed[2] = _convert_mps_to_proportional(speed[2]);</div><div class="line"><a name="l01106"></a><span class="lineno"> 1106</span>&#160;        speed[3] = _convert_mps_to_proportional(speed[3]);</div><div class="line"><a name="l01107"></a><span class="lineno"> 1107</span>&#160;</div><div class="line"><a name="l01108"></a><span class="lineno"> 1108</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;mecanum drive mode speed leftfront=%6.4f rightfront=%6.4f leftrear=%6.4f rightreer=%6.4f&quot;</span>, speed[0], speed[1], speed[2], speed[3]);</div><div class="line"><a name="l01109"></a><span class="lineno"> 1109</span>&#160;        <span class="keywordflow">break</span>;</div><div class="line"><a name="l01110"></a><span class="lineno"> 1110</span>&#160;</div><div class="line"><a name="l01111"></a><span class="lineno"> 1111</span>&#160;    <span class="keywordflow">default</span>:</div><div class="line"><a name="l01112"></a><span class="lineno"> 1112</span>&#160;        <span class="keywordflow">break</span>;</div><div class="line"><a name="l01113"></a><span class="lineno"> 1113</span>&#160;</div><div class="line"><a name="l01114"></a><span class="lineno"> 1114</span>&#160;    }</div><div class="line"><a name="l01115"></a><span class="lineno"> 1115</span>&#160;    </div><div class="line"><a name="l01116"></a><span class="lineno"> 1116</span>&#160;    <span class="comment">/* find all drive servos and set their new speed */</span></div><div class="line"><a name="l01117"></a><span class="lineno"> 1117</span>&#160;    <span class="keywordflow">for</span> (i=0; i&lt;(_last_servo); i++) {</div><div class="line"><a name="l01118"></a><span class="lineno"> 1118</span>&#160;        <span class="comment">// we use &#39;fall thru&#39; on the switch statement to allow all necessary servos to be controlled</span></div><div class="line"><a name="l01119"></a><span class="lineno"> 1119</span>&#160;        <span class="keywordflow">switch</span> (_active_drive.mode) {</div><div class="line"><a name="l01120"></a><span class="lineno"> 1120</span>&#160;        <span class="keywordflow">case</span> MODE_MECANUM:</div><div class="line"><a name="l01121"></a><span class="lineno"> 1121</span>&#160;            <span class="keywordflow">if</span> (_servo_configs[i].mode_pos == POSITION_LEFTREAR)</div><div class="line"><a name="l01122"></a><span class="lineno"> 1122</span>&#160;                _set_pwm_interval_proportional (i+1, speed[2]);</div><div class="line"><a name="l01123"></a><span class="lineno"> 1123</span>&#160;            <span class="keywordflow">if</span> (_servo_configs[i].mode_pos == POSITION_RIGHTREAR)</div><div class="line"><a name="l01124"></a><span class="lineno"> 1124</span>&#160;                _set_pwm_interval_proportional (i+1, speed[3]);</div><div class="line"><a name="l01125"></a><span class="lineno"> 1125</span>&#160;        <span class="keywordflow">case</span> MODE_DIFFERENTIAL:</div><div class="line"><a name="l01126"></a><span class="lineno"> 1126</span>&#160;            <span class="keywordflow">if</span> (_servo_configs[i].mode_pos == POSITION_LEFTFRONT)</div><div class="line"><a name="l01127"></a><span class="lineno"> 1127</span>&#160;                _set_pwm_interval_proportional (i+1, speed[0]);</div><div class="line"><a name="l01128"></a><span class="lineno"> 1128</span>&#160;        <span class="keywordflow">case</span> MODE_ACKERMAN:</div><div class="line"><a name="l01129"></a><span class="lineno"> 1129</span>&#160;            <span class="keywordflow">if</span> (_servo_configs[i].mode_pos == POSITION_RIGHTFRONT)</div><div class="line"><a name="l01130"></a><span class="lineno"> 1130</span>&#160;            _set_pwm_interval_proportional (i+1, speed[1]);</div><div class="line"><a name="l01131"></a><span class="lineno"> 1131</span>&#160;        }</div><div class="line"><a name="l01132"></a><span class="lineno"> 1132</span>&#160;    }</div><div class="line"><a name="l01133"></a><span class="lineno"> 1133</span>&#160;}</div><div class="line"><a name="l01134"></a><span class="lineno"> 1134</span>&#160;</div><div class="line"><a name="l01135"></a><span class="lineno"> 1135</span>&#160;</div><div class="line"><a name="l01136"></a><span class="lineno"> 1136</span>&#160;<span class="comment">// ------------------------------------------------------------------------------------------------------------------------------------</span></div><div class="line"><a name="l01141"></a><span class="lineno"> 1141</span>&#160;<span class="comment"></span><span class="comment">// services</span></div><div class="line"><a name="l01142"></a><span class="lineno"> 1142</span>&#160;<span class="comment">// ------------------------------------------------------------------------------------------------------------------------------------</span></div><div class="line"><a name="l01143"></a><span class="lineno"> 1143</span>&#160;</div><div class="line"><a name="l01172"></a><span class="lineno"><a class="line" href="group___services.html#ga948cb0dd7ba8c2ac4c7f2d2d93940d85"> 1172</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="group___services.html#ga948cb0dd7ba8c2ac4c7f2d2d93940d85">set_pwm_frequency</a> (i2cpwm_board::IntValue::Request &amp;req, i2cpwm_board::IntValue::Response &amp;res)</div><div class="line"><a name="l01173"></a><span class="lineno"> 1173</span>&#160;{</div><div class="line"><a name="l01174"></a><span class="lineno"> 1174</span>&#160;    <span class="keywordtype">int</span> freq;</div><div class="line"><a name="l01175"></a><span class="lineno"> 1175</span>&#160;    freq = req.value;</div><div class="line"><a name="l01176"></a><span class="lineno"> 1176</span>&#160;    <span class="keywordflow">if</span> ((freq&lt;12) || (freq&gt;1024)) {</div><div class="line"><a name="l01177"></a><span class="lineno"> 1177</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Invalid PWM frequency %d :: PWM frequencies should be between 12 and 1024&quot;</span>, freq);</div><div class="line"><a name="l01178"></a><span class="lineno"> 1178</span>&#160;        freq = 50;  <span class="comment">// most analog RC servos are designed for 20ms pulses.</span></div><div class="line"><a name="l01179"></a><span class="lineno"> 1179</span>&#160;        res.error = freq;</div><div class="line"><a name="l01180"></a><span class="lineno"> 1180</span>&#160;    }</div><div class="line"><a name="l01181"></a><span class="lineno"> 1181</span>&#160;    _set_pwm_frequency (freq);  <span class="comment">// I think we must reset frequency when we change boards</span></div><div class="line"><a name="l01182"></a><span class="lineno"> 1182</span>&#160;    res.error = freq;</div><div class="line"><a name="l01183"></a><span class="lineno"> 1183</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l01184"></a><span class="lineno"> 1184</span>&#160;}</div><div class="line"><a name="l01185"></a><span class="lineno"> 1185</span>&#160;</div><div class="line"><a name="l01186"></a><span class="lineno"> 1186</span>&#160;</div><div class="line"><a name="l01228"></a><span class="lineno"><a class="line" href="group___services.html#gabf512716d4497c6a4cb7bf9c5d94e2f1"> 1228</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="group___services.html#gabf512716d4497c6a4cb7bf9c5d94e2f1">config_servos</a> (i2cpwm_board::ServosConfig::Request &amp;req, i2cpwm_board::ServosConfig::Response &amp;res)</div><div class="line"><a name="l01229"></a><span class="lineno"> 1229</span>&#160;{</div><div class="line"><a name="l01230"></a><span class="lineno"> 1230</span>&#160;    <span class="comment">/* this service works on the active_board */</span></div><div class="line"><a name="l01231"></a><span class="lineno"> 1231</span>&#160;    <span class="keywordtype">int</span> i;</div><div class="line"><a name="l01232"></a><span class="lineno"> 1232</span>&#160;    </div><div class="line"><a name="l01233"></a><span class="lineno"> 1233</span>&#160;    res.error = 0;</div><div class="line"><a name="l01234"></a><span class="lineno"> 1234</span>&#160;</div><div class="line"><a name="l01235"></a><span class="lineno"> 1235</span>&#160;    <span class="keywordflow">if</span> ((_active_board&lt;1) || (_active_board&gt;62)) {</div><div class="line"><a name="l01236"></a><span class="lineno"> 1236</span>&#160;        ROS_ERROR(<span class="stringliteral">&quot;Internal error - invalid board number %d :: PWM board numbers must be between 1 and 62&quot;</span>, _active_board);</div><div class="line"><a name="l01237"></a><span class="lineno"> 1237</span>&#160;        res.error = -1;</div><div class="line"><a name="l01238"></a><span class="lineno"> 1238</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l01239"></a><span class="lineno"> 1239</span>&#160;    }</div><div class="line"><a name="l01240"></a><span class="lineno"> 1240</span>&#160;</div><div class="line"><a name="l01241"></a><span class="lineno"> 1241</span>&#160;    <span class="keywordflow">for</span> (i=0;i&lt;req.servos.size();i++) {</div><div class="line"><a name="l01242"></a><span class="lineno"> 1242</span>&#160;        <span class="keywordtype">int</span> servo = req.servos[i].servo;</div><div class="line"><a name="l01243"></a><span class="lineno"> 1243</span>&#160;        <span class="keywordtype">int</span> center = req.servos[i].center;</div><div class="line"><a name="l01244"></a><span class="lineno"> 1244</span>&#160;        <span class="keywordtype">int</span> range = req.servos[i].range;</div><div class="line"><a name="l01245"></a><span class="lineno"> 1245</span>&#160;        <span class="keywordtype">int</span> direction = req.servos[i].direction;</div><div class="line"><a name="l01246"></a><span class="lineno"> 1246</span>&#160;</div><div class="line"><a name="l01247"></a><span class="lineno"> 1247</span>&#160;        _config_servo (servo, center, range, direction);</div><div class="line"><a name="l01248"></a><span class="lineno"> 1248</span>&#160;    }</div><div class="line"><a name="l01249"></a><span class="lineno"> 1249</span>&#160;    </div><div class="line"><a name="l01250"></a><span class="lineno"> 1250</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l01251"></a><span class="lineno"> 1251</span>&#160;}</div><div class="line"><a name="l01252"></a><span class="lineno"> 1252</span>&#160;</div><div class="line"><a name="l01253"></a><span class="lineno"> 1253</span>&#160;</div><div class="line"><a name="l01327"></a><span class="lineno"><a class="line" href="group___services.html#gae3222f92a0cd33b0d0a2fcfd6d563ba9"> 1327</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="group___services.html#gae3222f92a0cd33b0d0a2fcfd6d563ba9">config_drive_mode</a> (i2cpwm_board::DriveMode::Request &amp;req, i2cpwm_board::DriveMode::Response &amp;res)</div><div class="line"><a name="l01328"></a><span class="lineno"> 1328</span>&#160;{</div><div class="line"><a name="l01329"></a><span class="lineno"> 1329</span>&#160;    res.error = 0;</div><div class="line"><a name="l01330"></a><span class="lineno"> 1330</span>&#160;</div><div class="line"><a name="l01331"></a><span class="lineno"> 1331</span>&#160;    <span class="keywordtype">int</span> i;</div><div class="line"><a name="l01332"></a><span class="lineno"> 1332</span>&#160;</div><div class="line"><a name="l01333"></a><span class="lineno"> 1333</span>&#160;    <span class="keywordflow">if</span> ((res.error = _config_drive_mode (req.mode, req.rpm, req.radius, req.track, req.scale)))</div><div class="line"><a name="l01334"></a><span class="lineno"> 1334</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l01335"></a><span class="lineno"> 1335</span>&#160;</div><div class="line"><a name="l01336"></a><span class="lineno"> 1336</span>&#160;    <span class="keywordflow">for</span> (i=0;i&lt;req.servos.size();i++) {</div><div class="line"><a name="l01337"></a><span class="lineno"> 1337</span>&#160;        <span class="keywordtype">int</span> servo = req.servos[i].servo;</div><div class="line"><a name="l01338"></a><span class="lineno"> 1338</span>&#160;        <span class="keywordtype">int</span> position = req.servos[i].position;</div><div class="line"><a name="l01339"></a><span class="lineno"> 1339</span>&#160;</div><div class="line"><a name="l01340"></a><span class="lineno"> 1340</span>&#160;        <span class="keywordflow">if</span> (_config_servo_position (servo, position) != 0) {</div><div class="line"><a name="l01341"></a><span class="lineno"> 1341</span>&#160;            res.error = servo; <span class="comment">/* this needs to be more specific and indicate a bad server ID was provided */</span></div><div class="line"><a name="l01342"></a><span class="lineno"> 1342</span>&#160;            <span class="keywordflow">continue</span>;</div><div class="line"><a name="l01343"></a><span class="lineno"> 1343</span>&#160;        }</div><div class="line"><a name="l01344"></a><span class="lineno"> 1344</span>&#160;    }</div><div class="line"><a name="l01345"></a><span class="lineno"> 1345</span>&#160;</div><div class="line"><a name="l01346"></a><span class="lineno"> 1346</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l01347"></a><span class="lineno"> 1347</span>&#160;}</div><div class="line"><a name="l01348"></a><span class="lineno"> 1348</span>&#160;</div><div class="line"><a name="l01349"></a><span class="lineno"> 1349</span>&#160;</div><div class="line"><a name="l01350"></a><span class="lineno"> 1350</span>&#160;</div><div class="line"><a name="l01370"></a><span class="lineno"><a class="line" href="group___services.html#ga4583b417d172bde68e75db603da3362e"> 1370</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="group___services.html#ga4583b417d172bde68e75db603da3362e">stop_servos</a> (std_srvs::Empty::Request&amp; req, std_srvs::Empty::Response&amp; res)</div><div class="line"><a name="l01371"></a><span class="lineno"> 1371</span>&#160;{</div><div class="line"><a name="l01372"></a><span class="lineno"> 1372</span>&#160;    <span class="keywordtype">int</span> save_active = _active_board;</div><div class="line"><a name="l01373"></a><span class="lineno"> 1373</span>&#160;    <span class="keywordtype">int</span> i;</div><div class="line"><a name="l01374"></a><span class="lineno"> 1374</span>&#160;</div><div class="line"><a name="l01375"></a><span class="lineno"> 1375</span>&#160;    <span class="keywordflow">for</span> (i=0; i&lt;MAX_BOARDS; i++) {</div><div class="line"><a name="l01376"></a><span class="lineno"> 1376</span>&#160;        <span class="keywordflow">if</span> (_pwm_boards[i] &gt; 0) {</div><div class="line"><a name="l01377"></a><span class="lineno"> 1377</span>&#160;            _set_active_board (i+1);    <span class="comment">// API is ONE based</span></div><div class="line"><a name="l01378"></a><span class="lineno"> 1378</span>&#160;            _set_pwm_interval_all (0, 0);</div><div class="line"><a name="l01379"></a><span class="lineno"> 1379</span>&#160;        }</div><div class="line"><a name="l01380"></a><span class="lineno"> 1380</span>&#160;    }</div><div class="line"><a name="l01381"></a><span class="lineno"> 1381</span>&#160;    _set_active_board (save_active);    <span class="comment">// restore last active board</span></div><div class="line"><a name="l01382"></a><span class="lineno"> 1382</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l01383"></a><span class="lineno"> 1383</span>&#160;}</div><div class="line"><a name="l01384"></a><span class="lineno"> 1384</span>&#160;</div><div class="line"><a name="l01385"></a><span class="lineno"> 1385</span>&#160;</div><div class="line"><a name="l01386"></a><span class="lineno"> 1386</span>&#160;</div><div class="line"><a name="l01387"></a><span class="lineno"> 1387</span>&#160;</div><div class="line"><a name="l01388"></a><span class="lineno"> 1388</span>&#160;</div><div class="line"><a name="l01389"></a><span class="lineno"> 1389</span>&#160;<span class="keyword">static</span> std::string _get_string_param (XmlRpc::XmlRpcValue obj, std::string param_name)</div><div class="line"><a name="l01390"></a><span class="lineno"> 1390</span>&#160;{</div><div class="line"><a name="l01391"></a><span class="lineno"> 1391</span>&#160;    XmlRpc::XmlRpcValue &amp;item = obj[param_name];</div><div class="line"><a name="l01392"></a><span class="lineno"> 1392</span>&#160;    <span class="keywordflow">if</span> (item.getType() == XmlRpc::XmlRpcValue::TypeString)</div><div class="line"><a name="l01393"></a><span class="lineno"> 1393</span>&#160;        <span class="keywordflow">return</span> item;</div><div class="line"><a name="l01394"></a><span class="lineno"> 1394</span>&#160;</div><div class="line"><a name="l01395"></a><span class="lineno"> 1395</span>&#160;    ROS_WARN(<span class="stringliteral">&quot;invalid paramter type for %s - expected TypeString&quot;</span>, param_name.c_str());</div><div class="line"><a name="l01396"></a><span class="lineno"> 1396</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l01397"></a><span class="lineno"> 1397</span>&#160;}</div><div class="line"><a name="l01398"></a><span class="lineno"> 1398</span>&#160;</div><div class="line"><a name="l01399"></a><span class="lineno"> 1399</span>&#160;    </div><div class="line"><a name="l01400"></a><span class="lineno"> 1400</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _get_int_param (XmlRpc::XmlRpcValue obj, std::string param_name)</div><div class="line"><a name="l01401"></a><span class="lineno"> 1401</span>&#160;{</div><div class="line"><a name="l01402"></a><span class="lineno"> 1402</span>&#160;    XmlRpc::XmlRpcValue &amp;item = obj[param_name];</div><div class="line"><a name="l01403"></a><span class="lineno"> 1403</span>&#160;    <span class="keywordflow">if</span> (item.getType() == XmlRpc::XmlRpcValue::TypeInt)</div><div class="line"><a name="l01404"></a><span class="lineno"> 1404</span>&#160;        <span class="keywordflow">return</span> item;</div><div class="line"><a name="l01405"></a><span class="lineno"> 1405</span>&#160;</div><div class="line"><a name="l01406"></a><span class="lineno"> 1406</span>&#160;    ROS_WARN(<span class="stringliteral">&quot;invalid paramter type for %s - expected TypeInt&quot;</span>, param_name.c_str());</div><div class="line"><a name="l01407"></a><span class="lineno"> 1407</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l01408"></a><span class="lineno"> 1408</span>&#160;}</div><div class="line"><a name="l01409"></a><span class="lineno"> 1409</span>&#160;</div><div class="line"><a name="l01410"></a><span class="lineno"> 1410</span>&#160;    </div><div class="line"><a name="l01411"></a><span class="lineno"> 1411</span>&#160;<span class="keyword">static</span> <span class="keywordtype">double</span> _get_float_param (XmlRpc::XmlRpcValue obj, std::string param_name)</div><div class="line"><a name="l01412"></a><span class="lineno"> 1412</span>&#160;{</div><div class="line"><a name="l01413"></a><span class="lineno"> 1413</span>&#160;    XmlRpc::XmlRpcValue &amp;item = obj[param_name];</div><div class="line"><a name="l01414"></a><span class="lineno"> 1414</span>&#160;    <span class="keywordflow">if</span> (item.getType() == XmlRpc::XmlRpcValue::TypeDouble)</div><div class="line"><a name="l01415"></a><span class="lineno"> 1415</span>&#160;        <span class="keywordflow">return</span> item;</div><div class="line"><a name="l01416"></a><span class="lineno"> 1416</span>&#160;</div><div class="line"><a name="l01417"></a><span class="lineno"> 1417</span>&#160;    ROS_WARN(<span class="stringliteral">&quot;invalid paramter type for %s - expected TypeDouble&quot;</span>, param_name.c_str());</div><div class="line"><a name="l01418"></a><span class="lineno"> 1418</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l01419"></a><span class="lineno"> 1419</span>&#160;}</div><div class="line"><a name="l01420"></a><span class="lineno"> 1420</span>&#160;</div><div class="line"><a name="l01421"></a><span class="lineno"> 1421</span>&#160;    </div><div class="line"><a name="l01422"></a><span class="lineno"> 1422</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _load_params (<span class="keywordtype">void</span>)</div><div class="line"><a name="l01423"></a><span class="lineno"> 1423</span>&#160;{       </div><div class="line"><a name="l01424"></a><span class="lineno"> 1424</span>&#160;    ros::NodeHandle nhp;                    <span class="comment">// not currently private namespace</span></div><div class="line"><a name="l01425"></a><span class="lineno"> 1425</span>&#160;</div><div class="line"><a name="l01426"></a><span class="lineno"> 1426</span>&#160;    <span class="comment">/*</span></div><div class="line"><a name="l01427"></a><span class="lineno"> 1427</span>&#160;<span class="comment">      pwm_frequency: 50</span></div><div class="line"><a name="l01428"></a><span class="lineno"> 1428</span>&#160;<span class="comment">    */</span></div><div class="line"><a name="l01429"></a><span class="lineno"> 1429</span>&#160;</div><div class="line"><a name="l01430"></a><span class="lineno"> 1430</span>&#160;    <span class="keywordtype">int</span> pwm;</div><div class="line"><a name="l01431"></a><span class="lineno"> 1431</span>&#160;    nhp.param (<span class="stringliteral">&quot;pwm_frequency&quot;</span>, pwm, 50);</div><div class="line"><a name="l01432"></a><span class="lineno"> 1432</span>&#160;</div><div class="line"><a name="l01433"></a><span class="lineno"> 1433</span>&#160;    </div><div class="line"><a name="l01434"></a><span class="lineno"> 1434</span>&#160;    <span class="comment">/*</span></div><div class="line"><a name="l01435"></a><span class="lineno"> 1435</span>&#160;<span class="comment">      // note: servos are numbered sequntially with &#39;1&#39; being the first servo on board #1, &#39;17&#39; is the first servo on board #2</span></div><div class="line"><a name="l01436"></a><span class="lineno"> 1436</span>&#160;<span class="comment"></span></div><div class="line"><a name="l01437"></a><span class="lineno"> 1437</span>&#160;<span class="comment">      servo_config:</span></div><div class="line"><a name="l01438"></a><span class="lineno"> 1438</span>&#160;<span class="comment">        - {id: 1, center: 333, direction: -1, range: 100}</span></div><div class="line"><a name="l01439"></a><span class="lineno"> 1439</span>&#160;<span class="comment">        - {id: 2, center: 336, direction: 1, range: 108}</span></div><div class="line"><a name="l01440"></a><span class="lineno"> 1440</span>&#160;<span class="comment"></span></div><div class="line"><a name="l01441"></a><span class="lineno"> 1441</span>&#160;<span class="comment">    */</span></div><div class="line"><a name="l01442"></a><span class="lineno"> 1442</span>&#160;    <span class="comment">// attempt to load configuration for servos</span></div><div class="line"><a name="l01443"></a><span class="lineno"> 1443</span>&#160;    <span class="keywordflow">if</span>(nhp.hasParam (<span class="stringliteral">&quot;servo_config&quot;</span>)) {</div><div class="line"><a name="l01444"></a><span class="lineno"> 1444</span>&#160;        XmlRpc::XmlRpcValue servos;</div><div class="line"><a name="l01445"></a><span class="lineno"> 1445</span>&#160;        nhp.getParam (<span class="stringliteral">&quot;servo_config&quot;</span>, servos);</div><div class="line"><a name="l01446"></a><span class="lineno"> 1446</span>&#160;</div><div class="line"><a name="l01447"></a><span class="lineno"> 1447</span>&#160;        <span class="keywordflow">if</span>(servos.getType() == XmlRpc::XmlRpcValue::TypeArray) {</div><div class="line"><a name="l01448"></a><span class="lineno"> 1448</span>&#160;            ROS_DEBUG(<span class="stringliteral">&quot;Retrieving members from &#39;servo_config&#39; in namespace(%s)&quot;</span>, nhp.getNamespace().c_str());</div><div class="line"><a name="l01449"></a><span class="lineno"> 1449</span>&#160;                </div><div class="line"><a name="l01450"></a><span class="lineno"> 1450</span>&#160;            <span class="keywordflow">for</span>(int32_t i = 0; i &lt; servos.size(); i++) {</div><div class="line"><a name="l01451"></a><span class="lineno"> 1451</span>&#160;                XmlRpc::XmlRpcValue servo;</div><div class="line"><a name="l01452"></a><span class="lineno"> 1452</span>&#160;                servo = servos[i];  <span class="comment">// get the data from the iterator</span></div><div class="line"><a name="l01453"></a><span class="lineno"> 1453</span>&#160;                <span class="keywordflow">if</span>(servo.getType() == XmlRpc::XmlRpcValue::TypeStruct) {</div><div class="line"><a name="l01454"></a><span class="lineno"> 1454</span>&#160;                    ROS_DEBUG(<span class="stringliteral">&quot;Retrieving items from &#39;servo_config&#39; member %d in namespace(%s)&quot;</span>, i, nhp.getNamespace().c_str());</div><div class="line"><a name="l01455"></a><span class="lineno"> 1455</span>&#160;</div><div class="line"><a name="l01456"></a><span class="lineno"> 1456</span>&#160;                    <span class="comment">// get the servo settings</span></div><div class="line"><a name="l01457"></a><span class="lineno"> 1457</span>&#160;                    <span class="keywordtype">int</span> <span class="keywordtype">id</span> = 0, center = 0, direction = 0, range = 0;</div><div class="line"><a name="l01458"></a><span class="lineno"> 1458</span>&#160;                    <span class="keywordtype">id</span> = _get_int_param (servo, <span class="stringliteral">&quot;id&quot;</span>);</div><div class="line"><a name="l01459"></a><span class="lineno"> 1459</span>&#160;                    center = _get_int_param (servo, <span class="stringliteral">&quot;center&quot;</span>);</div><div class="line"><a name="l01460"></a><span class="lineno"> 1460</span>&#160;                    direction = _get_int_param (servo, <span class="stringliteral">&quot;direction&quot;</span>);</div><div class="line"><a name="l01461"></a><span class="lineno"> 1461</span>&#160;                    range = _get_int_param (servo, <span class="stringliteral">&quot;range&quot;</span>);</div><div class="line"><a name="l01462"></a><span class="lineno"> 1462</span>&#160;                    </div><div class="line"><a name="l01463"></a><span class="lineno"> 1463</span>&#160;                    <span class="keywordflow">if</span> (<span class="keywordtype">id</span> &amp;&amp; center &amp;&amp; direction &amp;&amp; range) {</div><div class="line"><a name="l01464"></a><span class="lineno"> 1464</span>&#160;                        <span class="keywordflow">if</span> ((<span class="keywordtype">id</span> &gt;= 1) &amp;&amp; (<span class="keywordtype">id</span> &lt;= MAX_SERVOS)) {</div><div class="line"><a name="l01465"></a><span class="lineno"> 1465</span>&#160;                            <span class="keywordtype">int</span> board = ((int)(<span class="keywordtype">id</span> / 16)) + 1;</div><div class="line"><a name="l01466"></a><span class="lineno"> 1466</span>&#160;                            _set_active_board (board);</div><div class="line"><a name="l01467"></a><span class="lineno"> 1467</span>&#160;                            _set_pwm_frequency (pwm);</div><div class="line"><a name="l01468"></a><span class="lineno"> 1468</span>&#160;                            _config_servo (<span class="keywordtype">id</span>, center, range, direction);</div><div class="line"><a name="l01469"></a><span class="lineno"> 1469</span>&#160;                        }</div><div class="line"><a name="l01470"></a><span class="lineno"> 1470</span>&#160;                        <span class="keywordflow">else</span></div><div class="line"><a name="l01471"></a><span class="lineno"> 1471</span>&#160;                            ROS_WARN(<span class="stringliteral">&quot;Parameter servo id=%d is out of bounds&quot;</span>, <span class="keywordtype">id</span>);</div><div class="line"><a name="l01472"></a><span class="lineno"> 1472</span>&#160;                    }</div><div class="line"><a name="l01473"></a><span class="lineno"> 1473</span>&#160;                    <span class="keywordflow">else</span></div><div class="line"><a name="l01474"></a><span class="lineno"> 1474</span>&#160;                        ROS_WARN(<span class="stringliteral">&quot;Invalid parameters for servo id=%d&#39;&quot;</span>, <span class="keywordtype">id</span>);</div><div class="line"><a name="l01475"></a><span class="lineno"> 1475</span>&#160;                }</div><div class="line"><a name="l01476"></a><span class="lineno"> 1476</span>&#160;                <span class="keywordflow">else</span></div><div class="line"><a name="l01477"></a><span class="lineno"> 1477</span>&#160;                    ROS_WARN(<span class="stringliteral">&quot;Invalid type %d for member of &#39;servo_config&#39; - expected TypeStruct(%d)&quot;</span>, servo.getType(), XmlRpc::XmlRpcValue::TypeStruct);</div><div class="line"><a name="l01478"></a><span class="lineno"> 1478</span>&#160;            }</div><div class="line"><a name="l01479"></a><span class="lineno"> 1479</span>&#160;        }</div><div class="line"><a name="l01480"></a><span class="lineno"> 1480</span>&#160;        <span class="keywordflow">else</span></div><div class="line"><a name="l01481"></a><span class="lineno"> 1481</span>&#160;            ROS_WARN(<span class="stringliteral">&quot;Invalid type %d for &#39;servo_config&#39; - expected TypeArray(%d)&quot;</span>, servos.getType(), XmlRpc::XmlRpcValue::TypeArray);</div><div class="line"><a name="l01482"></a><span class="lineno"> 1482</span>&#160;    }</div><div class="line"><a name="l01483"></a><span class="lineno"> 1483</span>&#160;    <span class="keywordflow">else</span></div><div class="line"><a name="l01484"></a><span class="lineno"> 1484</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;Parameter Server namespace[%s] does not contain &#39;servo_config&quot;</span>, nhp.getNamespace().c_str());</div><div class="line"><a name="l01485"></a><span class="lineno"> 1485</span>&#160;</div><div class="line"><a name="l01486"></a><span class="lineno"> 1486</span>&#160;</div><div class="line"><a name="l01487"></a><span class="lineno"> 1487</span>&#160;    <span class="comment">/*</span></div><div class="line"><a name="l01488"></a><span class="lineno"> 1488</span>&#160;<span class="comment">      drive_config:</span></div><div class="line"><a name="l01489"></a><span class="lineno"> 1489</span>&#160;<span class="comment">        mode: mecanum</span></div><div class="line"><a name="l01490"></a><span class="lineno"> 1490</span>&#160;<span class="comment">        radius: 0.062</span></div><div class="line"><a name="l01491"></a><span class="lineno"> 1491</span>&#160;<span class="comment">        rpm: 60.0</span></div><div class="line"><a name="l01492"></a><span class="lineno"> 1492</span>&#160;<span class="comment">        scale: 0.3</span></div><div class="line"><a name="l01493"></a><span class="lineno"> 1493</span>&#160;<span class="comment">        track: 0.2</span></div><div class="line"><a name="l01494"></a><span class="lineno"> 1494</span>&#160;<span class="comment">        servos:</span></div><div class="line"><a name="l01495"></a><span class="lineno"> 1495</span>&#160;<span class="comment">            - {id: 1, position: 1}</span></div><div class="line"><a name="l01496"></a><span class="lineno"> 1496</span>&#160;<span class="comment">            - {id: 2, position: 2}</span></div><div class="line"><a name="l01497"></a><span class="lineno"> 1497</span>&#160;<span class="comment">            - {id: 3, position: 3}</span></div><div class="line"><a name="l01498"></a><span class="lineno"> 1498</span>&#160;<span class="comment">            - {id: 4, position: 4}</span></div><div class="line"><a name="l01499"></a><span class="lineno"> 1499</span>&#160;<span class="comment">    */</span></div><div class="line"><a name="l01500"></a><span class="lineno"> 1500</span>&#160;</div><div class="line"><a name="l01501"></a><span class="lineno"> 1501</span>&#160;    <span class="comment">// attempt to load configuration for drive mode</span></div><div class="line"><a name="l01502"></a><span class="lineno"> 1502</span>&#160;    <span class="keywordflow">if</span>(nhp.hasParam (<span class="stringliteral">&quot;drive_config&quot;</span>)) {</div><div class="line"><a name="l01503"></a><span class="lineno"> 1503</span>&#160;        XmlRpc::XmlRpcValue drive;</div><div class="line"><a name="l01504"></a><span class="lineno"> 1504</span>&#160;        nhp.getParam (<span class="stringliteral">&quot;drive_config&quot;</span>, drive);</div><div class="line"><a name="l01505"></a><span class="lineno"> 1505</span>&#160;</div><div class="line"><a name="l01506"></a><span class="lineno"> 1506</span>&#160;        <span class="keywordflow">if</span>(drive.getType() == XmlRpc::XmlRpcValue::TypeStruct) {</div><div class="line"><a name="l01507"></a><span class="lineno"> 1507</span>&#160;            ROS_DEBUG(<span class="stringliteral">&quot;Retrieving members from &#39;drive_config&#39; in namespace(%s)&quot;</span>, nhp.getNamespace().c_str());</div><div class="line"><a name="l01508"></a><span class="lineno"> 1508</span>&#160;</div><div class="line"><a name="l01509"></a><span class="lineno"> 1509</span>&#160;            <span class="comment">// get the drive mode settings</span></div><div class="line"><a name="l01510"></a><span class="lineno"> 1510</span>&#160;            std::string mode;</div><div class="line"><a name="l01511"></a><span class="lineno"> 1511</span>&#160;            <span class="keywordtype">float</span> radius, rpm, scale, track;</div><div class="line"><a name="l01512"></a><span class="lineno"> 1512</span>&#160;            <span class="keywordtype">int</span> id, position;</div><div class="line"><a name="l01513"></a><span class="lineno"> 1513</span>&#160;</div><div class="line"><a name="l01514"></a><span class="lineno"> 1514</span>&#160;            mode = _get_string_param (drive, <span class="stringliteral">&quot;mode&quot;</span>);</div><div class="line"><a name="l01515"></a><span class="lineno"> 1515</span>&#160;            rpm = _get_float_param (drive, <span class="stringliteral">&quot;rpm&quot;</span>);</div><div class="line"><a name="l01516"></a><span class="lineno"> 1516</span>&#160;            radius = _get_float_param (drive, <span class="stringliteral">&quot;radius&quot;</span>);</div><div class="line"><a name="l01517"></a><span class="lineno"> 1517</span>&#160;            track = _get_float_param (drive, <span class="stringliteral">&quot;track&quot;</span>);</div><div class="line"><a name="l01518"></a><span class="lineno"> 1518</span>&#160;            scale = _get_float_param (drive, <span class="stringliteral">&quot;scale&quot;</span>);</div><div class="line"><a name="l01519"></a><span class="lineno"> 1519</span>&#160;</div><div class="line"><a name="l01520"></a><span class="lineno"> 1520</span>&#160;            _config_drive_mode (mode, rpm, radius, track, scale);</div><div class="line"><a name="l01521"></a><span class="lineno"> 1521</span>&#160;</div><div class="line"><a name="l01522"></a><span class="lineno"> 1522</span>&#160;            XmlRpc::XmlRpcValue &amp;servos = drive[<span class="stringliteral">&quot;servos&quot;</span>];</div><div class="line"><a name="l01523"></a><span class="lineno"> 1523</span>&#160;            <span class="keywordflow">if</span>(servos.getType() == XmlRpc::XmlRpcValue::TypeArray) {</div><div class="line"><a name="l01524"></a><span class="lineno"> 1524</span>&#160;                ROS_DEBUG(<span class="stringliteral">&quot;Retrieving members from &#39;drive_config/servos&#39; in namespace(%s)&quot;</span>, nhp.getNamespace().c_str());</div><div class="line"><a name="l01525"></a><span class="lineno"> 1525</span>&#160;                </div><div class="line"><a name="l01526"></a><span class="lineno"> 1526</span>&#160;                <span class="keywordflow">for</span>(int32_t i = 0; i &lt; servos.size(); i++) {</div><div class="line"><a name="l01527"></a><span class="lineno"> 1527</span>&#160;                    XmlRpc::XmlRpcValue servo;</div><div class="line"><a name="l01528"></a><span class="lineno"> 1528</span>&#160;                    servo = servos[i];  <span class="comment">// get the data from the iterator</span></div><div class="line"><a name="l01529"></a><span class="lineno"> 1529</span>&#160;                    <span class="keywordflow">if</span>(servo.getType() == XmlRpc::XmlRpcValue::TypeStruct) {</div><div class="line"><a name="l01530"></a><span class="lineno"> 1530</span>&#160;                        ROS_DEBUG(<span class="stringliteral">&quot;Retrieving items from &#39;drive_config/servos&#39; member %d in namespace(%s)&quot;</span>, i, nhp.getNamespace().c_str());</div><div class="line"><a name="l01531"></a><span class="lineno"> 1531</span>&#160;</div><div class="line"><a name="l01532"></a><span class="lineno"> 1532</span>&#160;                        <span class="comment">// get the servo position settings</span></div><div class="line"><a name="l01533"></a><span class="lineno"> 1533</span>&#160;                        <span class="keywordtype">int</span> id, position;</div><div class="line"><a name="l01534"></a><span class="lineno"> 1534</span>&#160;                        <span class="keywordtype">id</span> = _get_int_param (servo, <span class="stringliteral">&quot;id&quot;</span>);</div><div class="line"><a name="l01535"></a><span class="lineno"> 1535</span>&#160;                        position = _get_int_param (servo, <span class="stringliteral">&quot;position&quot;</span>);</div><div class="line"><a name="l01536"></a><span class="lineno"> 1536</span>&#160;                    </div><div class="line"><a name="l01537"></a><span class="lineno"> 1537</span>&#160;                        <span class="keywordflow">if</span> (<span class="keywordtype">id</span> &amp;&amp; position)</div><div class="line"><a name="l01538"></a><span class="lineno"> 1538</span>&#160;                            _config_servo_position (<span class="keywordtype">id</span>, position); <span class="comment">// had its own error reporting</span></div><div class="line"><a name="l01539"></a><span class="lineno"> 1539</span>&#160;                    }</div><div class="line"><a name="l01540"></a><span class="lineno"> 1540</span>&#160;                    <span class="keywordflow">else</span></div><div class="line"><a name="l01541"></a><span class="lineno"> 1541</span>&#160;                        ROS_WARN(<span class="stringliteral">&quot;Invalid type %d for member %d of &#39;drive_config/servos&#39; - expected TypeStruct(%d)&quot;</span>, i, servo.getType(), XmlRpc::XmlRpcValue::TypeStruct);</div><div class="line"><a name="l01542"></a><span class="lineno"> 1542</span>&#160;                }</div><div class="line"><a name="l01543"></a><span class="lineno"> 1543</span>&#160;            }</div><div class="line"><a name="l01544"></a><span class="lineno"> 1544</span>&#160;            <span class="keywordflow">else</span></div><div class="line"><a name="l01545"></a><span class="lineno"> 1545</span>&#160;                ROS_WARN(<span class="stringliteral">&quot;Invalid type %d for &#39;drive_config/servos&#39; - expected TypeArray(%d)&quot;</span>, servos.getType(), XmlRpc::XmlRpcValue::TypeArray);</div><div class="line"><a name="l01546"></a><span class="lineno"> 1546</span>&#160;        }</div><div class="line"><a name="l01547"></a><span class="lineno"> 1547</span>&#160;        <span class="keywordflow">else</span></div><div class="line"><a name="l01548"></a><span class="lineno"> 1548</span>&#160;            ROS_WARN(<span class="stringliteral">&quot;Invalid type %d for &#39;drive_config&#39; - expected TypeStruct(%d)&quot;</span>, drive.getType(), XmlRpc::XmlRpcValue::TypeStruct);</div><div class="line"><a name="l01549"></a><span class="lineno"> 1549</span>&#160;    }</div><div class="line"><a name="l01550"></a><span class="lineno"> 1550</span>&#160;    <span class="keywordflow">else</span></div><div class="line"><a name="l01551"></a><span class="lineno"> 1551</span>&#160;        ROS_DEBUG(<span class="stringliteral">&quot;Parameter Server namespace[%s] does not contain &#39;drive_config&quot;</span>, nhp.getNamespace().c_str());</div><div class="line"><a name="l01552"></a><span class="lineno"> 1552</span>&#160;}   </div><div class="line"><a name="l01553"></a><span class="lineno"> 1553</span>&#160;</div><div class="line"><a name="l01554"></a><span class="lineno"> 1554</span>&#160;</div><div class="line"><a name="l01555"></a><span class="lineno"> 1555</span>&#160;<span class="comment">// ------------------------------------------------------------------------------------------------------------------------------------</span></div><div class="line"><a name="l01557"></a><span class="lineno"> 1557</span>&#160;<span class="comment"></span><span class="comment">// main</span></div><div class="line"><a name="l01558"></a><span class="lineno"> 1558</span>&#160;<span class="comment">// ------------------------------------------------------------------------------------------------------------------------------------</span></div><div class="line"><a name="l01559"></a><span class="lineno"> 1559</span>&#160;</div><div class="line"><a name="l01560"></a><span class="lineno"> 1560</span>&#160;<span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line"><a name="l01561"></a><span class="lineno"> 1561</span>&#160;{</div><div class="line"><a name="l01562"></a><span class="lineno"> 1562</span>&#160;</div><div class="line"><a name="l01563"></a><span class="lineno"> 1563</span>&#160;    _controller_io_handle = 0;</div><div class="line"><a name="l01564"></a><span class="lineno"> 1564</span>&#160;    _pwm_frequency = 50;        <span class="comment">// set the initial pulse frequency to 50 Hz which is standard for RC servos</span></div><div class="line"><a name="l01565"></a><span class="lineno"> 1565</span>&#160;</div><div class="line"><a name="l01566"></a><span class="lineno"> 1566</span>&#160;    </div><div class="line"><a name="l01567"></a><span class="lineno"> 1567</span>&#160;    _init (_CONST(<span class="stringliteral">&quot;/dev/i2c-1&quot;</span>));   <span class="comment">// default I2C device on RPi2 and RPi3 = &quot;/dev/i2c-1&quot;;</span></div><div class="line"><a name="l01568"></a><span class="lineno"> 1568</span>&#160;</div><div class="line"><a name="l01569"></a><span class="lineno"> 1569</span>&#160;    _set_active_board (1);</div><div class="line"><a name="l01570"></a><span class="lineno"> 1570</span>&#160;</div><div class="line"><a name="l01571"></a><span class="lineno"> 1571</span>&#160;    _set_pwm_frequency (50);</div><div class="line"><a name="l01572"></a><span class="lineno"> 1572</span>&#160;</div><div class="line"><a name="l01573"></a><span class="lineno"> 1573</span>&#160;</div><div class="line"><a name="l01574"></a><span class="lineno"> 1574</span>&#160;    ros::init (argc, argv, <span class="stringliteral">&quot;i2cpwm_controller&quot;</span>);</div><div class="line"><a name="l01575"></a><span class="lineno"> 1575</span>&#160;</div><div class="line"><a name="l01576"></a><span class="lineno"> 1576</span>&#160;    ros::NodeHandle n;</div><div class="line"><a name="l01577"></a><span class="lineno"> 1577</span>&#160;</div><div class="line"><a name="l01578"></a><span class="lineno"> 1578</span>&#160;    ros::ServiceServer freq_srv =       n.advertiseService  (<span class="stringliteral">&quot;set_pwm_frequency&quot;</span>,           <a class="code" href="group___services.html#ga948cb0dd7ba8c2ac4c7f2d2d93940d85">set_pwm_frequency</a>);</div><div class="line"><a name="l01579"></a><span class="lineno"> 1579</span>&#160;    ros::ServiceServer config_srv =     n.advertiseService  (<span class="stringliteral">&quot;config_servos&quot;</span>,               <a class="code" href="group___services.html#gabf512716d4497c6a4cb7bf9c5d94e2f1">config_servos</a>);         <span class="comment">// &#39;config&#39; will setup the necessary properties of continuous servos and is helpful for standard servos</span></div><div class="line"><a name="l01580"></a><span class="lineno"> 1580</span>&#160;    ros::ServiceServer mode_srv =       n.advertiseService  (<span class="stringliteral">&quot;config_drive_mode&quot;</span>,           <a class="code" href="group___services.html#gae3222f92a0cd33b0d0a2fcfd6d563ba9">config_drive_mode</a>);     <span class="comment">// &#39;mode&#39; specifies which servos are used for motion and which behavior will be applied when driving</span></div><div class="line"><a name="l01581"></a><span class="lineno"> 1581</span>&#160;    ros::ServiceServer stop_srv =       n.advertiseService  (<span class="stringliteral">&quot;stop_servos&quot;</span>,                 <a class="code" href="group___services.html#ga4583b417d172bde68e75db603da3362e">stop_servos</a>);           <span class="comment">// the &#39;stop&#39; service can be used at any time</span></div><div class="line"><a name="l01582"></a><span class="lineno"> 1582</span>&#160;</div><div class="line"><a name="l01583"></a><span class="lineno"> 1583</span>&#160;    ros::Subscriber abs_sub =           n.subscribe         (<span class="stringliteral">&quot;servos_absolute&quot;</span>, 500,        <a class="code" href="group___topics.html#gaa3fe8c6f5a98243c302c0d27cea219d9">servos_absolute</a>);       <span class="comment">// the &#39;absolute&#39; topic will be used for standard servo motion and testing of continuous servos</span></div><div class="line"><a name="l01584"></a><span class="lineno"> 1584</span>&#160;    ros::Subscriber rel_sub =           n.subscribe         (<span class="stringliteral">&quot;servos_proportional&quot;</span>, 500,    <a class="code" href="group___topics.html#ga1262b2e51072c237c51b6de4cb199e53">servos_proportional</a>);   <span class="comment">// the &#39;proportion&#39; topic will be used for standard servos and continuous rotation aka drive servos</span></div><div class="line"><a name="l01585"></a><span class="lineno"> 1585</span>&#160;    ros::Subscriber drive_sub =         n.subscribe         (<span class="stringliteral">&quot;servos_drive&quot;</span>, 500,           <a class="code" href="group___topics.html#gae257665eb64139d2720ed332e61507c6">servos_drive</a>);          <span class="comment">// the &#39;drive&#39; topic will be used for continuous rotation aka drive servos controlled by Twist messages</span></div><div class="line"><a name="l01586"></a><span class="lineno"> 1586</span>&#160;    </div><div class="line"><a name="l01587"></a><span class="lineno"> 1587</span>&#160;    _load_params();</div><div class="line"><a name="l01588"></a><span class="lineno"> 1588</span>&#160;    </div><div class="line"><a name="l01589"></a><span class="lineno"> 1589</span>&#160;    ros::spin();</div><div class="line"><a name="l01590"></a><span class="lineno"> 1590</span>&#160;</div><div class="line"><a name="l01591"></a><span class="lineno"> 1591</span>&#160;    close (_controller_io_handle);</div><div class="line"><a name="l01592"></a><span class="lineno"> 1592</span>&#160;</div><div class="line"><a name="l01593"></a><span class="lineno"> 1593</span>&#160;  <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l01594"></a><span class="lineno"> 1594</span>&#160;}</div><div class="line"><a name="l01595"></a><span class="lineno"> 1595</span>&#160;</div><div class="ttc" id="group___services_html_ga948cb0dd7ba8c2ac4c7f2d2d93940d85"><div class="ttname"><a href="group___services.html#ga948cb0dd7ba8c2ac4c7f2d2d93940d85">set_pwm_frequency</a></div><div class="ttdeci">bool set_pwm_frequency(i2cpwm_board::IntValue::Request &amp;req, i2cpwm_board::IntValue::Response &amp;res)</div><div class="ttdoc">service to set set PWM frequency </div><div class="ttdef"><b>Definition:</b> <a href="i2cpwm__controller_8cpp_source.html#l01172">i2cpwm_controller.cpp:1172</a></div></div>
<div class="ttc" id="group___services_html_gabf512716d4497c6a4cb7bf9c5d94e2f1"><div class="ttname"><a href="group___services.html#gabf512716d4497c6a4cb7bf9c5d94e2f1">config_servos</a></div><div class="ttdeci">bool config_servos(i2cpwm_board::ServosConfig::Request &amp;req, i2cpwm_board::ServosConfig::Response &amp;res)</div><div class="ttdoc">store configuration data for servos on the active board </div><div class="ttdef"><b>Definition:</b> <a href="i2cpwm__controller_8cpp_source.html#l01228">i2cpwm_controller.cpp:1228</a></div></div>
<div class="ttc" id="group___services_html_ga4583b417d172bde68e75db603da3362e"><div class="ttname"><a href="group___services.html#ga4583b417d172bde68e75db603da3362e">stop_servos</a></div><div class="ttdeci">bool stop_servos(std_srvs::Empty::Request &amp;req, std_srvs::Empty::Response &amp;res)</div><div class="ttdoc">service to stop all servos on all boards </div><div class="ttdef"><b>Definition:</b> <a href="i2cpwm__controller_8cpp_source.html#l01370">i2cpwm_controller.cpp:1370</a></div></div>
<div class="ttc" id="group___services_html_gae3222f92a0cd33b0d0a2fcfd6d563ba9"><div class="ttname"><a href="group___services.html#gae3222f92a0cd33b0d0a2fcfd6d563ba9">config_drive_mode</a></div><div class="ttdeci">bool config_drive_mode(i2cpwm_board::DriveMode::Request &amp;req, i2cpwm_board::DriveMode::Response &amp;res)</div><div class="ttdoc">set drive mode and drive servos </div><div class="ttdef"><b>Definition:</b> <a href="i2cpwm__controller_8cpp_source.html#l01327">i2cpwm_controller.cpp:1327</a></div></div>
<div class="ttc" id="group___topics_html_gae257665eb64139d2720ed332e61507c6"><div class="ttname"><a href="group___topics.html#gae257665eb64139d2720ed332e61507c6">servos_drive</a></div><div class="ttdeci">void servos_drive(const geometry_msgs::Twist::ConstPtr &amp;msg)</div><div class="ttdoc">subscriber topic to move servos based on a drive mode </div><div class="ttdef"><b>Definition:</b> <a href="i2cpwm__controller_8cpp_source.html#l00976">i2cpwm_controller.cpp:976</a></div></div>
<div class="ttc" id="group___topics_html_gaa3fe8c6f5a98243c302c0d27cea219d9"><div class="ttname"><a href="group___topics.html#gaa3fe8c6f5a98243c302c0d27cea219d9">servos_absolute</a></div><div class="ttdeci">void servos_absolute(const i2cpwm_board::ServoArray::ConstPtr &amp;msg)</div><div class="ttdoc">subscriber topic to move servos in a physical position </div><div class="ttdef"><b>Definition:</b> <a href="i2cpwm__controller_8cpp_source.html#l00797">i2cpwm_controller.cpp:797</a></div></div>
<div class="ttc" id="group___topics_html_ga1262b2e51072c237c51b6de4cb199e53"><div class="ttname"><a href="group___topics.html#ga1262b2e51072c237c51b6de4cb199e53">servos_proportional</a></div><div class="ttdeci">void servos_proportional(const i2cpwm_board::ServoArray::ConstPtr &amp;msg)</div><div class="ttdoc">subscriber topic to move servos in the range of ±1.0 </div><div class="ttdef"><b>Definition:</b> <a href="i2cpwm__controller_8cpp_source.html#l00867">i2cpwm_controller.cpp:867</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.11-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>
